BxTimelineModule.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406
  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_DEFAULT', BX_BASE_MOD_NTFS_TYPE_OWNER);
  16. define('BX_TIMELINE_VIEW_ITEM', 'item');
  17. define('BX_TIMELINE_VIEW_TIMELINE', 'timeline');
  18. define('BX_TIMELINE_VIEW_OUTLINE', 'outline');
  19. define('BX_TIMELINE_VIEW_SEARCH', 'search');
  20. define('BX_TIMELINE_VIEW_DEFAULT', BX_TIMELINE_VIEW_OUTLINE);
  21. define('BX_TIMELINE_FILTER_ALL', 'all');
  22. define('BX_TIMELINE_FILTER_OWNER', 'owner');
  23. define('BX_TIMELINE_FILTER_OTHER', 'other');
  24. define('BX_TIMELINE_PARSE_TYPE_POST', 'post');
  25. define('BX_TIMELINE_PARSE_TYPE_REPOST', 'repost');
  26. define('BX_TIMELINE_PARSE_TYPE_DEFAULT', BX_TIMELINE_PARSE_TYPE_POST);
  27. define('BX_TIMELINE_MEDIA_PHOTO', 'photo');
  28. define('BX_TIMELINE_MEDIA_VIDEO', 'video');
  29. //--- Video Auto Play
  30. define('BX_TIMELINE_VAP_OFF', 'off');
  31. define('BX_TIMELINE_VAP_ON_MUTE', 'on_mute');
  32. define('BX_TIMELINE_VAP_ON', 'on');
  33. class BxTimelineModule extends BxBaseModNotificationsModule implements iBxDolContentInfoService
  34. {
  35. protected $_sJsPostObject;
  36. protected $_sJsViewObject;
  37. protected $_aPostElements;
  38. protected $_sJsOutlineObject;
  39. protected $_sDividerTemplate;
  40. protected $_sBalloonTemplate;
  41. protected $_sCmtPostTemplate;
  42. protected $_sCmtViewTemplate;
  43. protected $_sCmtTemplate;
  44. /**
  45. * Constructor
  46. */
  47. function __construct($aModule)
  48. {
  49. parent::__construct($aModule);
  50. }
  51. /**
  52. * ACTION METHODS
  53. */
  54. public function actionVideo($iEventId, $iVideoId)
  55. {
  56. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iEventId));
  57. if(empty($aEvent) || !is_array($aEvent) || !$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']))
  58. return;
  59. $aData = $this->_oTemplate->getData($aEvent);
  60. if($aData === false || !isset($aData['content']['videos'][$iVideoId]))
  61. return;
  62. $oTemplate = $this->_oTemplate;
  63. $oTemplate->setPageNameIndex (BX_PAGE_CLEAR);
  64. $oTemplate->setPageContent ('page_main_code', $this->_oTemplate->getVideo($aEvent, $aData['content']['videos'][$iVideoId]));
  65. $oTemplate->getPageCode();
  66. }
  67. public function actionPost()
  68. {
  69. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  70. $mixedAllowed = $this->isAllowedPost(true);
  71. if($mixedAllowed !== true)
  72. return echoJson(array('message' => strip_tags($mixedAllowed)));
  73. echoJson($this->getFormPost());
  74. }
  75. public function actionEdit($iId)
  76. {
  77. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  78. $mixedAllowed = $this->isAllowedPost(true);
  79. if($mixedAllowed !== true)
  80. return echoJson(array('message' => strip_tags($mixedAllowed)));
  81. echoJson($this->getFormEdit($iId));
  82. }
  83. function actionPin()
  84. {
  85. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  86. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  87. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  88. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['pinned'] == 0 ? 'Pin' : 'Unpin')}($aEvent, true);
  89. if($mixedAllowed !== true)
  90. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  91. $aEvent['pinned'] = (int)$aEvent['pinned'] == 0 ? time() : 0;
  92. if(!$this->_oDb->updateEvent(array('pinned' => $aEvent['pinned']), array('id' => $iId)))
  93. return echoJson(array('code' => 2));
  94. echoJson(array(
  95. 'code' => 0,
  96. 'id' => $iId,
  97. 'eval' => $this->_oConfig->getJsObject('view') . '.onPinPost(oData)'
  98. ));
  99. }
  100. function actionPromote()
  101. {
  102. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  103. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  104. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  105. $mixedAllowed = $this->{'isAllowed' . ((int)$aEvent['promoted'] == 0 ? 'Promote' : 'Unpromote')}($aEvent, true);
  106. if($mixedAllowed !== true)
  107. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  108. $aEvent['promoted'] = (int)$aEvent['promoted'] == 0 ? time() : 0;
  109. if(!$this->_oDb->updateEvent(array('promoted' => $aEvent['promoted']), array('id' => $iId)))
  110. return echoJson(array('code' => 2));
  111. echoJson(array(
  112. 'code' => 0,
  113. 'message' => _t('_bx_timeline_txt_msg_performed_action')
  114. ));
  115. }
  116. function actionDelete()
  117. {
  118. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  119. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => bx_process_input(bx_get('id'), BX_DATA_INT)));
  120. $mixedAllowed = $this->isAllowedDelete($aEvent, true);
  121. if($mixedAllowed !== true)
  122. return echoJson(array('code' => 1, 'message' => strip_tags($mixedAllowed)));
  123. if(!$this->deleteEvent($aEvent))
  124. return echoJson(array('code' => 2));
  125. echoJson(array(
  126. 'code' => 0,
  127. 'id' => $aEvent['id'],
  128. 'eval' => $this->_oConfig->getJsObject('view') . '.onDeletePost(oData)'
  129. ));
  130. }
  131. public function actionRepost()
  132. {
  133. $iAuthorId = $this->getUserId();
  134. $iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  135. $aContent = array(
  136. 'type' => bx_process_input(bx_get('type'), BX_DATA_TEXT),
  137. 'action' => bx_process_input(bx_get('action'), BX_DATA_TEXT),
  138. 'object_id' => bx_process_input(bx_get('object_id'), BX_DATA_INT),
  139. );
  140. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  141. if(empty($aReposted) || !is_array($aReposted)) {
  142. echoJson(array('code' => 1, 'message' => _t('_bx_timeline_txt_err_cannot_repost')));
  143. return;
  144. }
  145. $mixedAllowed = $this->isAllowedRepost($aReposted, true);
  146. if($mixedAllowed !== true) {
  147. echoJson(array('code' => 2, 'message' => strip_tags($mixedAllowed)));
  148. return;
  149. }
  150. $bReposted = $this->_oDb->isReposted($aReposted['id'], $iOwnerId, $iAuthorId);
  151. if($bReposted) {
  152. echoJson(array('code' => 3, 'message' => _t('_bx_timeline_txt_err_already_reposted')));
  153. return;
  154. }
  155. $iId = $this->_oDb->insertEvent(array(
  156. 'owner_id' => $iOwnerId,
  157. 'type' => $this->_oConfig->getPrefix('common_post') . 'repost',
  158. 'action' => '',
  159. 'object_id' => $iAuthorId,
  160. 'object_privacy_view' => $this->_oConfig->getPrivacyViewDefault('object'),
  161. 'content' => serialize($aContent),
  162. 'title' => '',
  163. 'description' => ''
  164. ));
  165. if(empty($iId)) {
  166. echoJson(array('code' => 4, 'message' => _t('_bx_timeline_txt_err_cannot_repost')));
  167. return;
  168. }
  169. $this->onRepost($iId, $aReposted);
  170. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  171. $sCounter = $this->_oTemplate->getRepostCounter($aReposted);
  172. echoJson(array(
  173. 'code' => 0,
  174. 'message' => _t('_bx_timeline_txt_msg_success_repost'),
  175. 'count' => $aReposted['reposts'],
  176. 'counter' => $sCounter,
  177. 'disabled' => !$bReposted
  178. ));
  179. }
  180. function actionGetPost()
  181. {
  182. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  183. $sJsObject = bx_process_input(bx_get('js_object'));
  184. if(empty($sJsObject))
  185. $sJsObject = $this->_oConfig->getJsObject('post');
  186. $sView = bx_process_input(bx_get('view'));
  187. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  188. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  189. if(empty($aEvent) || !is_array($aEvent))
  190. return echoJson(array());
  191. echoJson(array(
  192. 'id' => $aEvent['id'],
  193. 'view' => $sView,
  194. 'item' => $this->_oTemplate->getPost($aEvent, array(
  195. 'view' => $sView,
  196. 'type' => 'owner',
  197. 'owner_id' => $this->_iOwnerId,
  198. 'dynamic_mode' => true
  199. )),
  200. 'eval' => $sJsObject . "._onGetPost(oData)"
  201. ));
  202. }
  203. function actionGetPosts()
  204. {
  205. $aParams = $this->_prepareParamsGet();
  206. list($sItems, $sLoadMore, $sBack, $sEmpty) = $this->_oTemplate->getPosts($aParams);
  207. echoJson(array(
  208. 'view' => $aParams['view'],
  209. 'items' => $sItems,
  210. 'load_more' => $sLoadMore,
  211. 'back' => $sBack,
  212. 'empty' => $sEmpty,
  213. 'eval' => $this->_oConfig->getJsObject('view') . "._onGetPosts(oData)"
  214. ));
  215. }
  216. public function actionGetPostForm()
  217. {
  218. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  219. echoJson($this->getFormPost());
  220. }
  221. public function actionGetEditForm($iId)
  222. {
  223. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  224. echoJson($this->getFormEdit($iId));
  225. }
  226. public function actionGetComments()
  227. {
  228. $this->_iOwnerId = bx_process_input(bx_get('owner_id'), BX_DATA_INT);
  229. $sSystem = bx_process_input(bx_get('system'), BX_DATA_TEXT);
  230. $iId = bx_process_input(bx_get('id'), BX_DATA_INT);
  231. $sComments = $this->_oTemplate->getComments($sSystem, $iId, true);
  232. echoJson(array('content' => $sComments));
  233. }
  234. public function actionAddAttachLink()
  235. {
  236. $sUrl = bx_process_input(bx_get('url'));
  237. if(empty($sUrl))
  238. return echoJson(array());
  239. echoJson($this->addAttachLink(array(
  240. 'url' => $sUrl
  241. )));
  242. }
  243. public function actionDeleteAttachLink()
  244. {
  245. $iUserId = $this->getUserId();
  246. $iLinkId = bx_process_input(bx_get('id'), BX_DATA_INT);
  247. if(empty($iLinkId)) {
  248. echoJson(array());
  249. return;
  250. }
  251. $aLink = $this->_oDb->getUnusedLinks($iUserId, $iLinkId);
  252. if(empty($aLink) || !is_array($aLink)) {
  253. echoJson(array());
  254. return;
  255. }
  256. if(!empty($aLink['media_id']))
  257. BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'))->deleteFile($aLink['media_id']);
  258. $aResult = array();
  259. if($this->_oDb->deleteUnusedLinks($iUserId, $iLinkId))
  260. $aResult = array('code' => 0);
  261. else
  262. $aResult = array('code' => 1, 'message' => _t('_bx_timeline_form_post_input_link_err_delete'));
  263. echoJson($aResult);
  264. }
  265. public function actionGetAttachLinkForm()
  266. {
  267. echo $this->_oTemplate->getAttachLinkForm();
  268. }
  269. public function actionSubmitAttachLinkForm()
  270. {
  271. echoJson($this->getFormAttachLink());
  272. }
  273. public function actionGetRepostedBy()
  274. {
  275. $iRepostedId = bx_process_input(bx_get('id'), BX_DATA_INT);
  276. echo $this->_oTemplate->getRepostedBy($iRepostedId);
  277. }
  278. public function actionGetItemBrief()
  279. {
  280. echo BxDolPage::getObjectInstance($this->_oConfig->getObject('page_item_brief'), $this->_oTemplate)->getCode();
  281. }
  282. function actionRss()
  283. {
  284. $aArgs = func_get_args();
  285. $sType = array_shift($aArgs);
  286. $iOwnerId = 0;
  287. switch($sType) {
  288. case BX_BASE_MOD_NTFS_TYPE_OWNER:
  289. $iOwnerId = array_shift($aArgs);
  290. list($sUserName) = $this->getUserInfo($iOwnerId);
  291. $sRssCaption = _t('_bx_timeline_txt_rss_caption', $sUserName);
  292. $sRssLink = $this->_oConfig->getViewUrl($iOwnerId);
  293. break;
  294. case BX_BASE_MOD_NTFS_TYPE_PUBLIC:
  295. $sRssCaption = _t('_bx_timeline_page_title_view_home');
  296. $sRssLink = $this->_oConfig->getHomeViewUrl();
  297. break;
  298. }
  299. $aParams = $this->_prepareParams(BX_TIMELINE_VIEW_DEFAULT, $sType, $iOwnerId, 0, $this->_oConfig->getRssLength(), '', array(), 0);
  300. $aEvents = $this->_oDb->getEvents($aParams);
  301. $aRssData = array();
  302. foreach($aEvents as $aEvent) {
  303. if(empty($aEvent['title'])) continue;
  304. $aRssData[$aEvent['id']] = array(
  305. 'UnitID' => $aEvent['id'],
  306. 'UnitTitle' => $aEvent['title'],
  307. 'UnitLink' => $this->_oConfig->getItemViewUrl($aEvent),
  308. 'UnitDesc' => $aEvent['description'],
  309. 'UnitDateTimeUTS' => $aEvent['date'],
  310. );
  311. }
  312. $oRss = new BxDolRssFactory();
  313. header('Content-Type: application/xml; charset=utf-8');
  314. echo $oRss->GenRssByData($aRssData, $sRssCaption, $sRssLink);
  315. }
  316. /**
  317. * SERVICE METHODS
  318. */
  319. /**
  320. * @page service Service Calls
  321. * @section bx_timeline Timeline
  322. * @subsection bx_timeline-other Other
  323. * @subsubsection bx_timeline-get_author get_author
  324. *
  325. * @code bx_srv('bx_timeline', 'get_author', [...]); @endcode
  326. *
  327. * Get author ID from content info by content ID. Is used in "Content Info Objects" system.
  328. *
  329. * @param $iContentId integer value with content ID.
  330. * @return integer value with author ID.
  331. *
  332. * @see BxTimelineModule::serviceGetAuthor
  333. */
  334. /**
  335. * @ref bx_timeline-get_author "get_author"
  336. */
  337. public function serviceGetAuthor ($iContentId)
  338. {
  339. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  340. if(empty($aEvent) || !is_array($aEvent))
  341. return 0;
  342. return $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']) ? (int)$aEvent['owner_id'] : (int)$aEvent['object_id'];
  343. }
  344. /**
  345. * @page service Service Calls
  346. * @section bx_timeline Timeline
  347. * @subsection bx_timeline-other Other
  348. * @subsubsection bx_timeline-get_date_changed get_date_changed
  349. *
  350. * @code bx_srv('bx_timeline', 'get_date_changed', [...]); @endcode
  351. *
  352. * Get date when the content was changed last time. Is used in "Content Info Objects" system.
  353. * Note. In case of Timeline event 0 is returned everytime.
  354. *
  355. * @param $iContentId integer value with content ID.
  356. * @return integer value with changing date.
  357. *
  358. * @see BxTimelineModule::serviceGetDateChanged
  359. */
  360. /**
  361. * @ref bx_timeline-get_date_changed "get_date_changed"
  362. */
  363. public function serviceGetDateChanged ($iContentId)
  364. {
  365. return 0;
  366. }
  367. /**
  368. * @page service Service Calls
  369. * @section bx_timeline Timeline
  370. * @subsection bx_timeline-other Other
  371. * @subsubsection bx_timeline-get_link get_link
  372. *
  373. * @code bx_srv('bx_timeline', 'get_link', [...]); @endcode
  374. *
  375. * Get content view page link. Is used in "Content Info Objects" system.
  376. *
  377. * @param $iContentId integer value with content ID.
  378. * @return string value with view page link.
  379. *
  380. * @see BxTimelineModule::serviceGetLink
  381. */
  382. /**
  383. * @ref bx_timeline-get_link "get_link"
  384. */
  385. public function serviceGetLink ($iContentId)
  386. {
  387. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  388. if(empty($aEvent) || !is_array($aEvent))
  389. return '';
  390. return $this->_oConfig->getItemViewUrl($aEvent);
  391. }
  392. /**
  393. * @page service Service Calls
  394. * @section bx_timeline Timeline
  395. * @subsection bx_timeline-other Other
  396. * @subsubsection bx_timeline-get_thumb get_thumb
  397. *
  398. * @code bx_srv('bx_timeline', 'get_thumb', [...]); @endcode
  399. *
  400. * Get content thumbnail link. Is used in "Content Info Objects" system.
  401. * Note. In case of Timeline event an empty string is returned everytime.
  402. *
  403. * @param $iContentId integer value with content ID.
  404. * @param $sTranscoder (optional) string value with transcoder name which should be applied to thumbnail image.
  405. * @return string value with thumbnail link.
  406. *
  407. * @see BxTimelineModule::serviceGetThumb
  408. */
  409. /**
  410. * @ref bx_timeline-get_thumb "get_thumb"
  411. */
  412. public function serviceGetThumb ($iContentId, $sTranscoder = '')
  413. {
  414. return '';
  415. }
  416. /**
  417. * @page service Service Calls
  418. * @section bx_timeline Timeline
  419. * @subsection bx_timeline-other Other
  420. * @subsubsection bx_timeline-get_info get_info
  421. *
  422. * @code bx_srv('bx_timeline', 'get_info', [...]); @endcode
  423. *
  424. * Get content info by content ID. Is used in "Content Info Objects" system.
  425. *
  426. * @param $iContentId integer value with content ID.
  427. * @param $bSearchableFieldsOnly (optional) boolean value determining all info or "searchable fields" only will be returned.
  428. * @return an array with content info. Empty array is returned if something is wrong.
  429. *
  430. * @see BxTimelineModule::serviceGetInfo
  431. */
  432. /**
  433. * @ref bx_timeline-get_info "get_info"
  434. */
  435. public function serviceGetInfo ($iContentId, $bSearchableFieldsOnly = true)
  436. {
  437. $aContentInfo = $this->_oDb->getEvents(array(
  438. 'browse' => 'id',
  439. 'value' => $iContentId)
  440. );
  441. return BxDolContentInfo::formatFields($aContentInfo);
  442. }
  443. /**
  444. * @page service Service Calls
  445. * @section bx_timeline Timeline
  446. * @subsection bx_timeline-other Other
  447. * @subsubsection bx_timeline-get_search_result_unit get_search_result_unit
  448. *
  449. * @code bx_srv('bx_timeline', 'get_search_result_unit', [...]); @endcode
  450. *
  451. * Get search result unit by content ID. Is used in "Content Info Objects" system.
  452. *
  453. * @param $iContentId integer value with content ID.
  454. * @param $sUnitTemplate (optional) string value with template name.
  455. * @return HTML string with search result unit. Empty string is returned if something is wrong.
  456. *
  457. * @see BxTimelineModule::serviceGetSearchResultUnit
  458. */
  459. /**
  460. * @ref bx_timeline-get_search_result_unit "get_search_result_unit"
  461. */
  462. public function serviceGetSearchResultUnit ($iContentId, $sUnitTemplate = '')
  463. {
  464. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  465. if(empty($aEvent) || !is_array($aEvent))
  466. return '';
  467. if(empty($sUnitTemplate))
  468. $sUnitTemplate = 'unit.html';
  469. return $this->_oTemplate->unit($aEvent, true, $sUnitTemplate);
  470. }
  471. /**
  472. * @page service Service Calls
  473. * @section bx_timeline Timeline
  474. * @subsection bx_timeline-page_blocks Page Blocks
  475. * @subsubsection bx_timeline-get_block_post get_block_post
  476. *
  477. * @code bx_srv('bx_timeline', 'get_block_post', [...]); @endcode
  478. *
  479. * Get Post block for a separate page.
  480. *
  481. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  482. * @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.
  483. *
  484. * @see BxTimelineModule::serviceGetBlockPost
  485. */
  486. /**
  487. * @ref bx_timeline-get_block_post "get_block_post"
  488. */
  489. public function serviceGetBlockPost($iProfileId = 0)
  490. {
  491. if(empty($iProfileId) && bx_get('profile_id') !== false)
  492. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  493. if(empty($iProfileId) && isLogged())
  494. $iProfileId = bx_get_logged_profile_id();
  495. if(!$iProfileId)
  496. return array();
  497. return $this->_getBlockPost($iProfileId);
  498. }
  499. /**
  500. * @page service Service Calls
  501. * @section bx_timeline Timeline
  502. * @subsection bx_timeline-page_blocks Page Blocks
  503. * @subsubsection bx_timeline-get_block_post_profile get_block_post_profile
  504. *
  505. * @code bx_srv('bx_timeline', 'get_block_post_profile', [...]); @endcode
  506. *
  507. * Get Post block for the Profile page.
  508. *
  509. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  510. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  511. * @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.
  512. *
  513. * @see BxTimelineModule::serviceGetBlockPostProfile
  514. */
  515. /**
  516. * @ref bx_timeline-get_block_post_profile "get_block_post_profile"
  517. */
  518. public function serviceGetBlockPostProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0)
  519. {
  520. if(empty($sProfileModule))
  521. return array();
  522. if(empty($iProfileContentId) && bx_get('id') !== false)
  523. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  524. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  525. if(empty($oProfile))
  526. return array();
  527. return $this->_getBlockPost($oProfile->id());
  528. }
  529. /**
  530. * @page service Service Calls
  531. * @section bx_timeline Timeline
  532. * @subsection bx_timeline-page_blocks Page Blocks
  533. * @subsubsection bx_timeline-get_block_post_home get_block_post_home
  534. *
  535. * @code bx_srv('bx_timeline', 'get_block_post_home', [...]); @endcode
  536. *
  537. * Get Post block for site's Home page.
  538. *
  539. * @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.
  540. *
  541. * @see BxTimelineModule::serviceGetBlockPostHome
  542. */
  543. /**
  544. * @ref bx_timeline-get_block_post_home "get_block_post_home"
  545. */
  546. public function serviceGetBlockPostHome()
  547. {
  548. $iProfileId = 0;
  549. return $this->_getBlockPost($iProfileId, array(
  550. 'form_display' => 'form_display_post_add_public'
  551. ));
  552. }
  553. /**
  554. * @page service Service Calls
  555. * @section bx_timeline Timeline
  556. * @subsection bx_timeline-page_blocks Page Blocks
  557. * @subsubsection bx_timeline-get_block_post_account get_block_post_account
  558. *
  559. * @code bx_srv('bx_timeline', 'get_block_post_account', [...]); @endcode
  560. *
  561. * Get Post block for the Dashboard page.
  562. *
  563. * @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.
  564. *
  565. * @see BxTimelineModule::serviceGetBlockPostAccount
  566. */
  567. /**
  568. * @ref bx_timeline-get_block_post_account "get_block_post_account"
  569. */
  570. public function serviceGetBlockPostAccount()
  571. {
  572. if(!isLogged())
  573. return '';
  574. $iProfileId = $this->getProfileId();
  575. return $this->_getBlockPost($iProfileId);
  576. }
  577. /**
  578. * @page service Service Calls
  579. * @section bx_timeline Timeline
  580. * @subsection bx_timeline-page_blocks Page Blocks
  581. * @subsubsection bx_timeline-get_block_view get_block_view
  582. *
  583. * @code bx_srv('bx_timeline', 'get_block_view', [...]); @endcode
  584. *
  585. * Get Timeline View block for a separate page.
  586. *
  587. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  588. * @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.
  589. *
  590. * @see BxTimelineModule::serviceGetBlockView
  591. */
  592. /**
  593. * @ref bx_timeline-get_block_view "get_block_view"
  594. */
  595. public function serviceGetBlockView($iProfileId = 0)
  596. {
  597. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_TIMELINE);
  598. }
  599. /**
  600. * @page service Service Calls
  601. * @section bx_timeline Timeline
  602. * @subsection bx_timeline-page_blocks Page Blocks
  603. * @subsubsection bx_timeline-get_block_view_outline get_block_view_outline
  604. *
  605. * @code bx_srv('bx_timeline', 'get_block_view_outline', [...]); @endcode
  606. *
  607. * Get Outline View block for a separate page.
  608. *
  609. * @param $iProfileId (optional) profile ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  610. * @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.
  611. *
  612. * @see BxTimelineModule::serviceGetBlockViewOutline
  613. */
  614. /**
  615. * @ref bx_timeline-get_block_view_outline "get_block_view_outline"
  616. */
  617. public function serviceGetBlockViewOutline($iProfileId = 0)
  618. {
  619. return $this->_serviceGetBlockView($iProfileId, BX_TIMELINE_VIEW_OUTLINE);
  620. }
  621. /**
  622. * @page service Service Calls
  623. * @section bx_timeline Timeline
  624. * @subsection bx_timeline-page_blocks Page Blocks
  625. * @subsubsection bx_timeline-get_block_view_profile get_block_view_profile
  626. *
  627. * @code bx_srv('bx_timeline', 'get_block_view_profile', [...]); @endcode
  628. *
  629. * Get Timeline View block for the Profile page.
  630. *
  631. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  632. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  633. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  634. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  635. * @param $sFilter (optional) string value with filter name.
  636. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  637. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  638. * @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.
  639. *
  640. * @see BxTimelineModule::serviceGetBlockViewProfile
  641. */
  642. /**
  643. * @ref bx_timeline-get_block_view_profile "get_block_view_profile"
  644. */
  645. public function serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  646. {
  647. $sView = BX_TIMELINE_VIEW_TIMELINE;
  648. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  649. }
  650. /**
  651. * @page service Service Calls
  652. * @section bx_timeline Timeline
  653. * @subsection bx_timeline-page_blocks Page Blocks
  654. * @subsubsection bx_timeline-get_block_view_profile_outline get_block_view_profile_outline
  655. *
  656. * @code bx_srv('bx_timeline', 'get_block_view_profile_outline', [...]); @endcode
  657. *
  658. * Get Outline View block for the Profile page.
  659. *
  660. * @param $sProfileModule (optional) string value with profile based module name. Persons module is used by default.
  661. * @param $iProfileContentId (optional) profile's content ID. If empty value is provided, an attempt to get it from GET/POST arrays will be performed.
  662. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  663. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  664. * @param $sFilter (optional) string value with filter name.
  665. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  666. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  667. * @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.
  668. *
  669. * @see BxTimelineModule::serviceGetBlockViewProfileOutline
  670. */
  671. /**
  672. * @ref bx_timeline-get_block_view_profile_outline "get_block_view_profile_outline"
  673. */
  674. public function serviceGetBlockViewProfileOutline($sProfileModule = 'bx_persons', $iProfileContentId = 0, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  675. {
  676. $sView = BX_TIMELINE_VIEW_OUTLINE;
  677. return $this->_serviceGetBlockViewProfile($sProfileModule, $iProfileContentId, $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  678. }
  679. /**
  680. * @page service Service Calls
  681. * @section bx_timeline Timeline
  682. * @subsection bx_timeline-page_blocks Page Blocks
  683. * @subsubsection bx_timeline-get_block_view_home get_block_view_home
  684. *
  685. * @code bx_srv('bx_timeline', 'get_block_view_home', [...]); @endcode
  686. *
  687. * Get Timeline View block for site's Home page.
  688. *
  689. * @param $iProfileId (optional) profile ID. 0 should be used here.
  690. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  691. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  692. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  693. * @param $sFilter (optional) string value with filter name.
  694. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  695. * @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.
  696. *
  697. * @see BxTimelineModule::serviceGetBlockViewHome
  698. */
  699. /**
  700. * @ref bx_timeline-get_block_view_home "get_block_view_home"
  701. */
  702. public function serviceGetBlockViewHome($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  703. {
  704. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_TIMELINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  705. }
  706. /**
  707. * @page service Service Calls
  708. * @section bx_timeline Timeline
  709. * @subsection bx_timeline-page_blocks Page Blocks
  710. * @subsubsection bx_timeline-get_block_view_home_outline get_block_view_home_outline
  711. *
  712. * @code bx_srv('bx_timeline', 'get_block_view_home_outline', [...]); @endcode
  713. *
  714. * Get Outline View block for site's Home page.
  715. *
  716. * @param $iProfileId (optional) profile ID. 0 should be used here.
  717. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  718. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  719. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  720. * @param $sFilter (optional) string value with filter name.
  721. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  722. * @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.
  723. *
  724. * @see BxTimelineModule::serviceGetBlockViewHomeOutline
  725. */
  726. /**
  727. * @ref bx_timeline-get_block_view_home_outline "get_block_view_home_outline"
  728. */
  729. public function serviceGetBlockViewHomeOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  730. {
  731. return $this->_serviceGetBlockViewHome($iProfileId, BX_TIMELINE_VIEW_OUTLINE, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  732. }
  733. /**
  734. * @page service Service Calls
  735. * @section bx_timeline Timeline
  736. * @subsection bx_timeline-page_blocks Page Blocks
  737. * @subsubsection bx_timeline-get_block_view_account get_block_view_account
  738. *
  739. * @code bx_srv('bx_timeline', 'get_block_view_account', [...]); @endcode
  740. *
  741. * Get Timeline View block for the Dashboard page.
  742. *
  743. * @param $iProfileId (optional) profile ID. 0 should be used here.
  744. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  745. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  746. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  747. * @param $sFilter (optional) string value with filter name.
  748. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  749. * @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.
  750. *
  751. * @see BxTimelineModule::serviceGetBlockViewAccount
  752. */
  753. /**
  754. * @ref bx_timeline-get_block_view_account "get_block_view_account"
  755. */
  756. public function serviceGetBlockViewAccount($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  757. {
  758. if(!isLogged())
  759. return '';
  760. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_TIMELINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  761. }
  762. /**
  763. * @page service Service Calls
  764. * @section bx_timeline Timeline
  765. * @subsection bx_timeline-page_blocks Page Blocks
  766. * @subsubsection bx_timeline-get_block_view_account_outline get_block_view_account_outline
  767. *
  768. * @code bx_srv('bx_timeline', 'get_block_view_account_outline', [...]); @endcode
  769. *
  770. * Get Outline View block for the Dashboard page.
  771. *
  772. * @param $iProfileId (optional) profile ID. 0 should be used here.
  773. * @param $iStart (optional) integer value with a page number. Is used in pagination.
  774. * @param $iPerPage (optional) integer value with a number of items per page. Is used in pagination.
  775. * @param $iTimeline (optional) integer value determining whether the timeline should be displayed or not.
  776. * @param $sFilter (optional) string value with filter name.
  777. * @param $aModules (optional) an array of modules from which the events should be displayed. All available modules are used by default.
  778. * @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.
  779. *
  780. * @see BxTimelineModule::serviceGetBlockViewAccountOutline
  781. */
  782. /**
  783. * @ref bx_timeline-get_block_view_account_outline "get_block_view_account_outline"
  784. */
  785. public function serviceGetBlockViewAccountOutline($iProfileId = 0, $iStart = -1, $iPerPage = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  786. {
  787. if(!isLogged())
  788. return '';
  789. return $this->_serviceGetBlockViewByType($iProfileId, BX_TIMELINE_VIEW_OUTLINE, BX_TIMELINE_TYPE_OWNER_AND_CONNECTIONS, $iStart, $iPerPage, $this->_oConfig->getPerPage('account'), $iTimeline, $sFilter, $aModules);
  790. }
  791. /**
  792. * @page service Service Calls
  793. * @section bx_timeline Timeline
  794. * @subsection bx_timeline-page_blocks Page Blocks
  795. * @subsubsection bx_timeline-get_block_item get_block_item
  796. *
  797. * @code bx_srv('bx_timeline', 'get_block_item', [...]); @endcode
  798. *
  799. * Get View Item block.
  800. *
  801. * @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.
  802. *
  803. * @see BxTimelineModule::serviceGetBlockItem
  804. */
  805. /**
  806. * @ref bx_timeline-get_block_item "get_block_item"
  807. */
  808. public function serviceGetBlockItem()
  809. {
  810. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  811. if(!$iItemId)
  812. return array();
  813. return $this->_oTemplate->getItemBlock($iItemId);
  814. }
  815. public function serviceGetBlockItemContent()
  816. {
  817. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  818. $sMode = bx_process_input(bx_get('mode'));
  819. if(!$iItemId || !$sMode)
  820. return '';
  821. return $this->_oTemplate->getItemBlockContent($iItemId, $sMode);
  822. }
  823. public function serviceGetBlockItemInfo()
  824. {
  825. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  826. if(!$iItemId)
  827. return '';
  828. return $this->_oTemplate->getItemBlockInfo($iItemId);
  829. }
  830. public function serviceGetBlockItemComments()
  831. {
  832. $iItemId = bx_process_input(bx_get('id'), BX_DATA_INT);
  833. if(!$iItemId)
  834. return '';
  835. return $this->_oTemplate->getItemBlockComments($iItemId);
  836. }
  837. /**
  838. * @page service Service Calls
  839. * @section bx_timeline Timeline
  840. * @subsection bx_timeline-integration_notifications Integration with Notifications
  841. * @subsubsection bx_timeline-get_notifications_data get_notifications_data
  842. *
  843. * @code bx_srv('bx_timeline', 'get_notifications_data', [...]); @endcode
  844. *
  845. * Data for Notifications module.
  846. *
  847. * @return an array with special format.
  848. *
  849. * @see BxTimelineModule::serviceGetNotificationsData
  850. */
  851. /**
  852. * @ref bx_timeline-get_notifications_data "get_notifications_data"
  853. */
  854. public function serviceGetNotificationsData()
  855. {
  856. $sModule = $this->_aModule['name'];
  857. return array(
  858. 'handlers' => array(
  859. array('group' => $sModule . '_object', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'post_common', 'module_name' => $sModule, 'module_method' => 'get_notifications_post', 'module_class' => 'Module'),
  860. array('group' => $sModule . '_object', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete'),
  861. array('group' => $sModule . '_repost', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'repost', 'module_name' => $sModule, 'module_method' => 'get_notifications_repost', 'module_class' => 'Module'),
  862. array('group' => $sModule . '_repost', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'delete_repost'),
  863. array('group' => $sModule . '_comment', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'commentPost', 'module_name' => $sModule, 'module_method' => 'get_notifications_comment', 'module_class' => 'Module'),
  864. array('group' => $sModule . '_comment', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'commentRemoved'),
  865. array('group' => $sModule . '_vote', 'type' => 'insert', 'alert_unit' => $sModule, 'alert_action' => 'doVote', 'module_name' => $sModule, 'module_method' => 'get_notifications_vote', 'module_class' => 'Module'),
  866. array('group' => $sModule . '_vote', 'type' => 'delete', 'alert_unit' => $sModule, 'alert_action' => 'undoVote'),
  867. ),
  868. 'alerts' => array(
  869. array('unit' => $sModule, 'action' => 'post_common'),
  870. array('unit' => $sModule, 'action' => 'delete'),
  871. array('unit' => $sModule, 'action' => 'repost'),
  872. array('unit' => $sModule, 'action' => 'delete_repost'),
  873. array('unit' => $sModule, 'action' => 'commentPost'),
  874. array('unit' => $sModule, 'action' => 'commentRemoved'),
  875. array('unit' => $sModule, 'action' => 'doVote'),
  876. array('unit' => $sModule, 'action' => 'undoVote'),
  877. )
  878. );
  879. }
  880. /**
  881. * @page service Service Calls
  882. * @section bx_timeline Timeline
  883. * @subsection bx_timeline-integration_notifications Integration with Notifications
  884. * @subsubsection bx_timeline-get_notifications_repost get_notifications_repost
  885. *
  886. * @code bx_srv('bx_timeline', 'get_notifications_repost', [...]); @endcode
  887. *
  888. * Get data for Repost event to display in Notifications module.
  889. *
  890. * @param $aEvent an array with event description.
  891. * @return an array with special format.
  892. *
  893. * @see BxTimelineModule::serviceGetNotificationsRepost
  894. */
  895. /**
  896. * @ref bx_timeline-get_notifications_repost "get_notifications_repost"
  897. */
  898. public function serviceGetNotificationsRepost($aEvent)
  899. {
  900. $aResult = $this->serviceGetNotificationsPost($aEvent);
  901. $aResult['lang_key'] = '_bx_timeline_txt_object_reposted';
  902. return $aResult;
  903. }
  904. /**
  905. * @page service Service Calls
  906. * @section bx_timeline Timeline
  907. * @subsection bx_timeline-integration_notifications Integration with Notifications
  908. * @subsubsection bx_timeline-get_notifications_post get_notifications_post
  909. *
  910. * @code bx_srv('bx_timeline', 'get_notifications_post', [...]); @endcode
  911. *
  912. * Get data for Post event to display in Notifications module.
  913. *
  914. * @param $aEvent an array with event description.
  915. * @return an array with special format.
  916. *
  917. * @see BxTimelineModule::serviceGetNotificationsPost
  918. */
  919. /**
  920. * @ref bx_timeline-get_notifications_post "get_notifications_post"
  921. */
  922. public function serviceGetNotificationsPost($aEvent)
  923. {
  924. $CNF = &$this->_oConfig->CNF;
  925. $iContent = (int)$aEvent['object_id'];
  926. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  927. if(empty($aContent) || !is_array($aContent))
  928. return array();
  929. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  930. return array(
  931. 'entry_sample' => $CNF['T']['txt_sample_single_ext'],
  932. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  933. 'entry_caption' => $sEntryCaption,
  934. 'entry_author' => $aContent['owner_id'],
  935. 'lang_key' => '_bx_timeline_ntfs_txt_object_added', //may be empty or not specified. In this case the default one from Notification module will be used.
  936. );
  937. }
  938. /**
  939. * @page service Service Calls
  940. * @section bx_timeline Timeline
  941. * @subsection bx_timeline-integration_notifications Integration with Notifications
  942. * @subsubsection bx_timeline-get_notifications_comment get_notifications_comment
  943. *
  944. * @code bx_srv('bx_timeline', 'get_notifications_comment', [...]); @endcode
  945. *
  946. * Get data for Post Comment event to display in Notifications module.
  947. *
  948. * @param $aEvent an array with event description.
  949. * @return an array with special format.
  950. *
  951. * @see BxTimelineModule::serviceGetNotificationsComment
  952. */
  953. /**
  954. * @ref bx_timeline-get_notifications_comment "get_notifications_comment"
  955. */
  956. public function serviceGetNotificationsComment($aEvent)
  957. {
  958. $CNF = &$this->_oConfig->CNF;
  959. $iContent = (int)$aEvent['object_id'];
  960. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  961. if(empty($aContent) || !is_array($aContent))
  962. return array();
  963. $oComment = BxDolCmts::getObjectInstance($CNF['OBJECT_COMMENTS'], $iContent);
  964. if(!$oComment || !$oComment->isEnabled())
  965. return array();
  966. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  967. return array(
  968. 'entry_sample' => $CNF['T']['txt_sample_single'],
  969. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  970. 'entry_caption' => $sEntryCaption,
  971. 'entry_author' => $aContent['owner_id'],
  972. 'subentry_sample' => $CNF['T']['txt_sample_comment_single'],
  973. 'subentry_url' => $oComment->getViewUrl((int)$aEvent['subobject_id']),
  974. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  975. );
  976. }
  977. /**
  978. * @page service Service Calls
  979. * @section bx_timeline Timeline
  980. * @subsection bx_timeline-integration_notifications Integration with Notifications
  981. * @subsubsection bx_timeline-get_notifications_vote get_notifications_vote
  982. *
  983. * @code bx_srv('bx_timeline', 'get_notifications_vote', [...]); @endcode
  984. *
  985. * Get data for Vote event to display in Notifications module.
  986. *
  987. * @param $aEvent an array with event description.
  988. * @return an array with special format.
  989. *
  990. * @see BxTimelineModule::serviceGetNotificationsVote
  991. */
  992. /**
  993. * @ref bx_timeline-get_notifications_vote "get_notifications_vote"
  994. */
  995. public function serviceGetNotificationsVote($aEvent)
  996. {
  997. $CNF = &$this->_oConfig->CNF;
  998. $iContent = (int)$aEvent['object_id'];
  999. $aContent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContent));
  1000. if(empty($aContent) || !is_array($aContent))
  1001. return array();
  1002. $oVote = BxDolVote::getObjectInstance($CNF['OBJECT_VOTES'], $iContent);
  1003. if(!$oVote || !$oVote->isEnabled())
  1004. return array();
  1005. $sEntryCaption = !empty($aContent['title']) ? $aContent['title'] : $this->_oConfig->getTitle($aContent['description']);
  1006. return array(
  1007. 'entry_sample' => $CNF['T']['txt_sample_single'],
  1008. 'entry_url' => $this->_oConfig->getItemViewUrl($aContent),
  1009. 'entry_caption' => $sEntryCaption,
  1010. 'entry_author' => $aContent['owner_id'],
  1011. 'subentry_sample' => $CNF['T']['txt_sample_vote_single'],
  1012. 'lang_key' => '', //may be empty or not specified. In this case the default one from Notification module will be used.
  1013. );
  1014. }
  1015. /**
  1016. * @page service Service Calls
  1017. * @section bx_timeline Timeline
  1018. * @subsection bx_timeline-repost Repost
  1019. * @subsubsection bx_timeline-get_repost_element_block get_repost_element_block
  1020. *
  1021. * @code bx_srv('bx_timeline', 'get_repost_element_block', [...]); @endcode
  1022. *
  1023. * Get repost element for content based modules.
  1024. *
  1025. * @param $iOwnerId integer value with owner profile ID.
  1026. * @param $sType string value with type (module name).
  1027. * @param $sAction string value with action (module action).
  1028. * @param $iObjectId integer value with object ID to be reposted.
  1029. * @param $aParams (optional) an array with additional params.
  1030. * @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.
  1031. *
  1032. * @see BxTimelineModule::serviceGetRepostElementBlock
  1033. */
  1034. /**
  1035. * @ref bx_timeline-get_repost_element_block "get_repost_element_block"
  1036. */
  1037. public function serviceGetRepostElementBlock($iOwnerId, $sType, $sAction, $iObjectId, $aParams = array())
  1038. {
  1039. if(!$this->isEnabled())
  1040. return '';
  1041. $aParams = array_merge($this->_oConfig->getRepostDefaults(), $aParams);
  1042. return $this->_oTemplate->getRepostElement($iOwnerId, $sType, $sAction, $iObjectId, $aParams);
  1043. }
  1044. /**
  1045. * @page service Service Calls
  1046. * @section bx_timeline Timeline
  1047. * @subsection bx_timeline-repost Repost
  1048. * @subsubsection bx_timeline-get_repost_counter get_repost_counter
  1049. *
  1050. * @code bx_srv('bx_timeline', 'get_repost_counter', [...]); @endcode
  1051. *
  1052. * Get repost counter.
  1053. *
  1054. * @param $sType string value with type (module name).
  1055. * @param $sAction string value with action (module action).
  1056. * @param $iObjectId integer value with object ID to be reposted.
  1057. * @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.
  1058. *
  1059. * @see BxTimelineModule::serviceGetRepostCounter
  1060. */
  1061. /**
  1062. * @ref bx_timeline-get_repost_counter "get_repost_counter"
  1063. */
  1064. public function serviceGetRepostCounter($sType, $sAction, $iObjectId)
  1065. {
  1066. if(!$this->isEnabled())
  1067. return '';
  1068. $aReposted = $this->_oDb->getReposted($sType, $sAction, $iObjectId);
  1069. return $this->_oTemplate->getRepostCounter($aReposted);
  1070. }
  1071. /**
  1072. * @page service Service Calls
  1073. * @section bx_timeline Timeline
  1074. * @subsection bx_timeline-repost Repost
  1075. * @subsubsection bx_timeline-get_repost_js_script get_repost_js_script
  1076. *
  1077. * @code bx_srv('bx_timeline', 'get_repost_js_script', [...]); @endcode
  1078. *
  1079. * Get repost JavaScript code.
  1080. *
  1081. * @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.
  1082. *
  1083. * @see BxTimelineModule::serviceGetRepostJsScript
  1084. */
  1085. /**
  1086. * @ref bx_timeline-get_repost_js_script "get_repost_js_script"
  1087. */
  1088. public function serviceGetRepostJsScript()
  1089. {
  1090. if(!$this->isEnabled())
  1091. return '';
  1092. return $this->_oTemplate->getRepostJsScript();
  1093. }
  1094. /**
  1095. * @page service Service Calls
  1096. * @section bx_timeline Timeline
  1097. * @subsection bx_timeline-repost Repost
  1098. * @subsubsection bx_timeline-get_repost_js_click get_repost_js_click
  1099. *
  1100. * @code bx_srv('bx_timeline', 'get_repost_js_click', [...]); @endcode
  1101. *
  1102. * Get repost JavaScript code for OnClick event.
  1103. *
  1104. * @param $iOwnerId integer value with owner profile ID.
  1105. * @param $sType string value with type (module name).
  1106. * @param $sAction string value with action (module action).
  1107. * @param $iObjectId integer value with object ID to be reposted.
  1108. * @return HTML string with JavaScript code to display in OnClick events of HTML elements.
  1109. *
  1110. * @see BxTimelineModule::serviceGetRepostJsClick
  1111. */
  1112. /**
  1113. * @ref bx_timeline-get_repost_js_click "get_repost_js_click"
  1114. */
  1115. public function serviceGetRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId)
  1116. {
  1117. if(!$this->isEnabled())
  1118. return '';
  1119. return $this->_oTemplate->getRepostJsClick($iOwnerId, $sType, $sAction, $iObjectId);
  1120. }
  1121. /**
  1122. * @page service Service Calls
  1123. * @section bx_timeline Timeline
  1124. * @subsection bx_timeline-other Other
  1125. * @subsubsection bx_timeline-get_menu_item_addon_comment get_menu_item_addon_comment
  1126. *
  1127. * @code bx_srv('bx_timeline', 'get_menu_item_addon_comment', [...]); @endcode
  1128. *
  1129. * Get addon for Comment menu item.
  1130. *
  1131. * @param $sSystem string value with comments engine system.
  1132. * @param $iObjectId integer value with object ID.
  1133. * @return HTML string to display in menu item.
  1134. *
  1135. * @see BxTimelineModule::serviceGetMenuItemAddonComment
  1136. */
  1137. /**
  1138. * @ref bx_timeline-get_menu_item_addon_comment "get_menu_item_addon_comment"
  1139. */
  1140. public function serviceGetMenuItemAddonComment($sSystem, $iObjectId)
  1141. {
  1142. if(empty($sSystem) || empty($iObjectId))
  1143. return '';
  1144. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1145. if($oCmts === false)
  1146. return '';
  1147. $iCounter = (int)$oCmts->getCommentsCount();
  1148. return $this->_oTemplate->parseLink('javascript:void(0)', $iCounter > 0 ? $iCounter : '', array(
  1149. 'title' => _t('_bx_timeline_menu_item_title_item_comment'),
  1150. 'onclick' => "javascript:" . $this->_oConfig->getJsObject('view') . ".commentItem(this, '" . $sSystem . "', " . $iObjectId . ")"
  1151. ));
  1152. }
  1153. /**
  1154. * @page service Service Calls
  1155. * @section bx_timeline Timeline
  1156. * @subsection bx_timeline-other Other
  1157. * @subsubsection bx_timeline-get_settings_checker_helper get_settings_checker_helper
  1158. *
  1159. * @code bx_srv('bx_timeline', 'get_settings_checker_helper', [...]); @endcode
  1160. *
  1161. * Get Checker Helper class name for Forms engine.
  1162. *
  1163. * @return string with Checker Helper class name.
  1164. *
  1165. * @see BxTimelineModule::serviceGetSettingsCheckerHelper
  1166. */
  1167. /**
  1168. * @ref bx_timeline-get_settings_checker_helper "get_settings_checker_helper"
  1169. */
  1170. public function serviceGetSettingsCheckerHelper()
  1171. {
  1172. bx_import('FormCheckerHelper', $this->_aModule);
  1173. return 'BxTimelineFormCheckerHelper';
  1174. }
  1175. /**
  1176. * @page service Service Calls
  1177. * @section bx_timeline Timeline
  1178. * @subsection bx_timeline-other Other
  1179. * @subsubsection bx_timeline-get_options_videos_autoplay get_options_videos_autoplay
  1180. *
  1181. * @code bx_srv('bx_timeline', 'get_options_videos_autoplay', [...]); @endcode
  1182. *
  1183. * Get an array with available options for 'Videos autoplay in Timeline' setting.
  1184. *
  1185. * @return an array with available options represented as key => value pairs.
  1186. *
  1187. * @see BxTimelineModule::serviceGetOptionsVideosAutoplay
  1188. */
  1189. /**
  1190. * @ref bx_timeline-get_options_videos_autoplay "get_options_videos_autoplay"
  1191. */
  1192. public function serviceGetOptionsVideosAutoplay()
  1193. {
  1194. $aOptions = array(BX_TIMELINE_VAP_OFF, BX_TIMELINE_VAP_ON_MUTE, BX_TIMELINE_VAP_ON);
  1195. $aResult = array();
  1196. foreach($aOptions as $sOption)
  1197. $aResult[] = array(
  1198. 'key' => $sOption,
  1199. 'value' => _t('_bx_timeline_option_videos_autoplay_' . $sOption)
  1200. );
  1201. return $aResult;
  1202. }
  1203. /*
  1204. * COMMON METHODS
  1205. */
  1206. public function deleteEvent($aEvent)
  1207. {
  1208. if(empty($aEvent) || !is_array($aEvent) || !$this->_oDb->deleteEvent(array('id' => (int)$aEvent['id'])))
  1209. return false;
  1210. $this->onDelete($aEvent);
  1211. return true;
  1212. }
  1213. public function addAttachLink($aValues, $sDisplay = false)
  1214. {
  1215. $CNF = &$this->_oConfig->CNF;
  1216. if(!$sDisplay)
  1217. $sDisplay = $this->_oConfig->getObject('form_display_attach_link_add');
  1218. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $sDisplay, $this->_oTemplate);
  1219. if(!$oForm)
  1220. return array('message' => '_sys_txt_error_occured');
  1221. $oForm->aFormAttrs['method'] = BX_DOL_FORM_METHOD_SPECIFIC;
  1222. $oForm->aParams['csrf']['disable'] = true;
  1223. if(!empty($oForm->aParams['db']['submit_name'])) {
  1224. $sSubmitName = $oForm->aParams['db']['submit_name'];
  1225. if(!isset($oForm->aInputs[$sSubmitName])) {
  1226. if(isset($oForm->aInputs[$CNF['FIELD_CONTROLS']]))
  1227. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1228. if(!is_numeric($mixedIndex) || empty($aInput['name']) || $aInput['name'] != $sSubmitName)
  1229. continue;
  1230. $aValues[$sSubmitName] = $aInput['value'];
  1231. }
  1232. }
  1233. else
  1234. $aValues[$sSubmitName] = $oForm->aInputs[$sSubmitName]['value'];
  1235. }
  1236. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1237. $oForm->initChecker(array(), $aValues);
  1238. if(!$oForm->isSubmittedAndValid())
  1239. return array('message' => '_sys_txt_error_occured');
  1240. return $this->_addLink($oForm);
  1241. }
  1242. public function getFormAttachLink()
  1243. {
  1244. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject('form_attach_link'), $this->_oConfig->getObject('form_display_attach_link_add'), $this->_oTemplate);
  1245. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'submit_attach_link_form/';
  1246. $oForm->aInputs['url']['checker']['params']['preg'] = $this->_oConfig->getPregPattern('url');
  1247. $oForm->initChecker();
  1248. if($oForm->isSubmittedAndValid())
  1249. return $this->_addLink($oForm);
  1250. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1251. }
  1252. public function getFormPost($aParams = array())
  1253. {
  1254. $iUserId = $this->getUserId();
  1255. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1256. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_add';
  1257. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1258. $oForm->initChecker();
  1259. if($oForm->isSubmittedAndValid()) {
  1260. list($sUserName) = $this->getUserInfo($iUserId);
  1261. $sType = $oForm->getCleanValue('type');
  1262. $sType = $this->_oConfig->getPrefix('common_post') . $sType;
  1263. BxDolForm::setSubmittedValue('type', $sType, $oForm->aFormAttrs['method']);
  1264. $aContent = array();
  1265. //--- Process Text ---//
  1266. $sText = $oForm->getCleanValue('text');
  1267. $sText = $this->_prepareTextForSave($sText);
  1268. $bText = !empty($sText);
  1269. unset($oForm->aInputs['text']);
  1270. if($bText)
  1271. $aContent['text'] = $sText;
  1272. //--- Process Privacy ---//
  1273. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1274. if(empty($iObjectPrivacyView))
  1275. $iObjectPrivacyView = $this->_oConfig->getPrivacyViewDefault('object');
  1276. //--- Process Link ---//
  1277. $aLinkIds = $oForm->getCleanValue('link');
  1278. $bLinkIds = !empty($aLinkIds) && is_array($aLinkIds);
  1279. //--- Process Media ---//
  1280. $aPhotoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_PHOTO);
  1281. $bPhotoIds = !empty($aPhotoIds) && is_array($aPhotoIds);
  1282. $aVideoIds = $oForm->getCleanValue(BX_TIMELINE_MEDIA_VIDEO);
  1283. $bVideoIds = !empty($aVideoIds) && is_array($aVideoIds);
  1284. if(!$bText && !$bLinkIds && !$bPhotoIds && !$bVideoIds)
  1285. return array('message' => _t('_bx_timeline_txt_err_empty_post'));
  1286. $sTitle = $bText ? $this->_oConfig->getTitle($sText) : $this->_oTemplate->getItemIcon($bText, $bLinkIds, $bPhotoIds, $bVideoIds);
  1287. $sDescription = _t('_bx_timeline_txt_user_added_sample', $sUserName, _t('_bx_timeline_txt_sample_with_article'));
  1288. //--- Process Date ---//
  1289. $iDate = 0;
  1290. if(isset($oForm->aInputs['date']))
  1291. $iDate = $oForm->getCleanValue('date');
  1292. if(empty($iDate))
  1293. $iDate = time();
  1294. $iId = $oForm->insert(array(
  1295. 'object_id' => $iUserId,
  1296. 'object_privacy_view' => $iObjectPrivacyView,
  1297. 'content' => serialize($aContent),
  1298. 'title' => $sTitle,
  1299. 'description' => $sDescription,
  1300. 'date' => $iDate
  1301. ));
  1302. if(!empty($iId)) {
  1303. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1304. if($bText)
  1305. $oMetatags->metaAdd($iId, $sText);
  1306. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1307. //--- Process Link ---//
  1308. if($bLinkIds)
  1309. foreach($aLinkIds as $iLinkId)
  1310. $this->_oDb->saveLink($iId, $iLinkId);
  1311. //--- Process Media ---//
  1312. if($bPhotoIds)
  1313. $this->_saveMedia(BX_TIMELINE_MEDIA_PHOTO, $iId, $aPhotoIds);
  1314. if($bVideoIds)
  1315. $this->_saveMedia(BX_TIMELINE_MEDIA_VIDEO, $iId, $aVideoIds);
  1316. $this->onPost($iId);
  1317. return array('id' => $iId);
  1318. }
  1319. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1320. }
  1321. return array('form' => $oForm->getCode(), 'form_id' => $oForm->id);
  1322. }
  1323. public function getFormEdit($iId, $aParams = array())
  1324. {
  1325. $CNF = &$this->_oConfig->CNF;
  1326. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1327. if(empty($aEvent) || !is_array($aEvent))
  1328. return array();
  1329. $aContent = unserialize($aEvent['content']);
  1330. if(is_array($aContent) && !empty($aContent['text']))
  1331. $aEvent['text'] = $aContent['text'];
  1332. $sFormObject = !empty($aParams['form_object']) ? $aParams['form_object'] : 'form_post';
  1333. $sFormDisplay = !empty($aParams['form_display']) ? $aParams['form_display'] : 'form_display_post_edit';
  1334. $oForm = BxDolForm::getObjectInstance($this->_oConfig->getObject($sFormObject), $this->_oConfig->getObject($sFormDisplay), $this->_oTemplate);
  1335. $oForm->setId($this->_oConfig->getHtmlIds('view', 'edit_form') . $iId);
  1336. $oForm->aFormAttrs['action'] = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'edit/' . $iId ;
  1337. foreach($oForm->aInputs[$CNF['FIELD_CONTROLS']] as $mixedIndex => $aInput) {
  1338. if(!is_numeric($mixedIndex))
  1339. continue;
  1340. $oForm->aInputs[$CNF['FIELD_CONTROLS']][$mixedIndex]['attrs'] = bx_replace_markers($aInput['attrs'], array(
  1341. 'js_object_view' => $this->_oConfig->getJsObject('view'),
  1342. 'content_id' => $iId
  1343. ));
  1344. }
  1345. $oForm->initChecker($aEvent);
  1346. if($oForm->isSubmittedAndValid()) {
  1347. $aContent = array();
  1348. //--- Process Text ---//
  1349. $sText = $oForm->getCleanValue('text');
  1350. $sText = $this->_prepareTextForSave($sText);
  1351. $bText = !empty($sText);
  1352. unset($oForm->aInputs['text']);
  1353. if($bText)
  1354. $aContent['text'] = $sText;
  1355. //--- Process Privacy ---//
  1356. $iObjectPrivacyView = (int)$oForm->getCleanValue('object_privacy_view');
  1357. if(empty($iObjectPrivacyView))
  1358. $iObjectPrivacyView = $this->_oConfig->getPrivacyViewDefault('object');
  1359. $aValsToAdd = array(
  1360. 'object_privacy_view' => $iObjectPrivacyView,
  1361. 'content' => serialize($aContent)
  1362. );
  1363. //--- Process Date ---//
  1364. if(isset($oForm->aInputs['date'])) {
  1365. $iDate = $oForm->getCleanValue('date');
  1366. if(empty($iDate))
  1367. $iDate = time();
  1368. $aValsToAdd['date'] = $iDate;
  1369. }
  1370. if(!$oForm->update($iId, $aValsToAdd))
  1371. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1372. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1373. if($bText)
  1374. $oMetatags->metaAdd($iId, $sText);
  1375. $oMetatags->locationsAddFromForm($iId, $this->_oConfig->CNF['FIELD_LOCATION_PREFIX']);
  1376. return array(
  1377. 'id' => $iId,
  1378. 'eval' => $this->_oConfig->getJsObject('view') . '.onEditPostSubmit(oData)'
  1379. );
  1380. }
  1381. return array(
  1382. 'id' => $iId,
  1383. 'form' => $oForm->getCode(),
  1384. 'form_id' => $oForm->id,
  1385. 'eval' => $this->_oConfig->getJsObject('view') . '.onEditPost(oData)'
  1386. );
  1387. }
  1388. public function getCmtsObject($sSystem, $iId)
  1389. {
  1390. if(empty($sSystem) || (int)$iId == 0)
  1391. return false;
  1392. $oCmts = BxDolCmts::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1393. if(!$oCmts || !$oCmts->isEnabled())
  1394. return false;
  1395. return $oCmts;
  1396. }
  1397. public function getViewObject($sSystem, $iId)
  1398. {
  1399. if(empty($sSystem) || (int)$iId == 0)
  1400. return false;
  1401. $oView = BxDolView::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1402. if(!$oView || !$oView->isEnabled())
  1403. return false;
  1404. return $oView;
  1405. }
  1406. public function getVoteObject($sSystem, $iId)
  1407. {
  1408. if(empty($sSystem) || (int)$iId == 0)
  1409. return false;
  1410. $oVote = BxDolVote::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1411. if(!$oVote || !$oVote->isEnabled())
  1412. return false;
  1413. return $oVote;
  1414. }
  1415. public function getReportObject($sSystem, $iId)
  1416. {
  1417. if(empty($sSystem) || (int)$iId == 0)
  1418. return false;
  1419. $oReport = BxDolReport::getObjectInstance($sSystem, $iId, true, $this->_oTemplate);
  1420. if(!$oReport || !$oReport->isEnabled())
  1421. return false;
  1422. return $oReport;
  1423. }
  1424. public function getAttachmentsMenuObject()
  1425. {
  1426. $oMenu = BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_post_attachments'), $this->_oTemplate);
  1427. $oMenu->addMarkers(array(
  1428. 'js_object' => $this->_oConfig->getJsObject('post'),
  1429. ));
  1430. return $oMenu;
  1431. }
  1432. public function getManageMenuObject()
  1433. {
  1434. return BxDolMenu::getObjectInstance($this->_oConfig->getObject('menu_item_manage'), $this->_oTemplate);
  1435. }
  1436. //--- Check permissions methods ---//
  1437. public function isAllowedPost($bPerform = false)
  1438. {
  1439. if(isAdmin())
  1440. return true;
  1441. $iUserId = $this->getUserId();
  1442. $aCheckResult = checkActionModule($iUserId, 'post', $this->getName(), $bPerform);
  1443. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1444. if($oProfileOwner !== false) {
  1445. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1446. return _t('_sys_txt_access_denied');
  1447. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_post', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1448. }
  1449. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1450. }
  1451. public function isAllowedView($aEvent, $bPerform = false)
  1452. {
  1453. $CNF = $this->_oConfig->CNF;
  1454. $mixedResult = BxDolProfile::getInstance($aEvent[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  1455. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1456. return false;
  1457. return true;
  1458. }
  1459. public function isAllowedEdit($aEvent, $bPerform = false)
  1460. {
  1461. //--- System posts cannot be edited at all.
  1462. if(!isLogged() || !$this->_oConfig->isCommon($aEvent['type'], $aEvent['action']))
  1463. return false;
  1464. if(isAdmin())
  1465. return true;
  1466. $iUserId = (int)$this->getUserId();
  1467. $iOwnerId = (int)$aEvent['owner_id'];
  1468. $iObjectId = (int)$aEvent['object_id'];
  1469. if($iObjectId == $iUserId && $this->_oConfig->isAllowEdit())
  1470. return true;
  1471. $aCheckResult = checkActionModule($iUserId, 'edit', $this->getName(), $bPerform);
  1472. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  1473. if($oProfileOwner !== false)
  1474. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_edit', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1475. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1476. }
  1477. public function isAllowedDelete($aEvent, $bPerform = false)
  1478. {
  1479. if(!isLogged())
  1480. return false;
  1481. if(isAdmin())
  1482. return true;
  1483. $iUserId = (int)$this->getUserId();
  1484. $iOwnerId = (int)$aEvent['owner_id'];
  1485. $iObjectId = (int)$aEvent['object_id'];
  1486. if((($iOwnerId == $iUserId && $this->_oConfig->isAllowDelete()) || ($this->_oConfig->isCommon($aEvent['type'], $aEvent['action']) && $iObjectId == $iUserId)))
  1487. return true;
  1488. $aCheckResult = checkActionModule($iUserId, 'delete', $this->getName(), $bPerform);
  1489. $oProfileOwner = BxDolProfile::getInstance($iOwnerId);
  1490. if($oProfileOwner !== false)
  1491. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_delete', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1492. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1493. }
  1494. public function isAllowedComment($aEvent, $bPerform = false)
  1495. {
  1496. $mixedComments = $this->getCommentsData($aEvent['comments']);
  1497. if($mixedComments === false)
  1498. return false;
  1499. list($sSystem, $iObjectId) = $mixedComments;
  1500. $oCmts = $this->getCmtsObject($sSystem, $iObjectId);
  1501. $oCmts->addCssJs();
  1502. $bResult = true;
  1503. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1504. if($oProfileOwner !== false) {
  1505. if($oProfileOwner->checkAllowedPostInProfile() !== CHECK_ACTION_RESULT_ALLOWED)
  1506. return false;
  1507. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_comment', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1508. }
  1509. return $bResult;
  1510. }
  1511. public function isAllowedViewCounter($aEvent, $bPerform = false)
  1512. {
  1513. $mixedViews = $this->getViewsData($aEvent['views']);
  1514. if($mixedViews === false)
  1515. return false;
  1516. list($sSystem, $iObjectId) = $mixedViews;
  1517. $oView = $this->getViewObject($sSystem, $iObjectId);
  1518. $bResult = true;
  1519. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1520. if($oProfileOwner !== false)
  1521. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view_counter', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1522. return $bResult;
  1523. }
  1524. public function isAllowedVote($aEvent, $bPerform = false)
  1525. {
  1526. $mixedVotes = $this->getVotesData($aEvent['votes']);
  1527. if($mixedVotes === false)
  1528. return false;
  1529. list($sSystem, $iObjectId) = $mixedVotes;
  1530. $oVote = $this->getVoteObject($sSystem, $iObjectId);
  1531. $oVote->addCssJs();
  1532. $bResult = true;
  1533. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1534. if($oProfileOwner !== false)
  1535. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_vote', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1536. return $bResult;
  1537. }
  1538. public function isAllowedReport($aEvent, $bPerform = false)
  1539. {
  1540. $mixedReports = $this->getReportsData($aEvent['reports']);
  1541. if($mixedReports === false)
  1542. return false;
  1543. list($sSystem, $iObjectId) = $mixedReports;
  1544. $oReport = $this->getReportObject($sSystem, $iObjectId);
  1545. $oReport->addCssJs();
  1546. $bResult = true;
  1547. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1548. if($oProfileOwner !== false)
  1549. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_report', $oProfileOwner->id(), (int)$this->getUserId(), array('result' => &$bResult));
  1550. return $bResult;
  1551. }
  1552. public function isAllowedRepost($aEvent, $bPerform = false)
  1553. {
  1554. if(isAdmin())
  1555. return true;
  1556. $iUserId = (int)$this->getUserId();
  1557. if($iUserId == 0)
  1558. return false;
  1559. $aCheckResult = checkActionModule($iUserId, 'repost', $this->getName(), $bPerform);
  1560. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1561. if($oProfileOwner !== false)
  1562. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_repost', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1563. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1564. }
  1565. public function isAllowedSend($aEvent, $bPerform = false)
  1566. {
  1567. if(!$this->_oDb->isEnabledByName('bx_convos'))
  1568. return false;
  1569. if(isAdmin())
  1570. return true;
  1571. $iUserId = (int)$this->getUserId();
  1572. if($iUserId == 0)
  1573. return false;
  1574. $aCheckResult = checkActionModule($iUserId, 'send', $this->getName(), $bPerform);
  1575. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1576. if($oProfileOwner !== false)
  1577. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_send', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1578. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1579. }
  1580. public function isAllowedPin($aEvent, $bPerform = false)
  1581. {
  1582. if((int)$aEvent['pinned'] != 0)
  1583. return false;
  1584. return $this->_isAllowedPin($aEvent, $bPerform);
  1585. }
  1586. public function isAllowedUnpin($aEvent, $bPerform = false)
  1587. {
  1588. if((int)$aEvent['pinned'] == 0)
  1589. return false;
  1590. return $this->_isAllowedPin($aEvent, $bPerform);
  1591. }
  1592. public function isAllowedPromote($aEvent, $bPerform = false)
  1593. {
  1594. if((int)$aEvent['promoted'] != 0)
  1595. return false;
  1596. return $this->_isAllowedPromote($aEvent, $bPerform);
  1597. }
  1598. public function isAllowedUnpromote($aEvent, $bPerform = false)
  1599. {
  1600. if((int)$aEvent['promoted'] == 0)
  1601. return false;
  1602. return $this->_isAllowedPromote($aEvent, $bPerform);
  1603. }
  1604. public function isAllowedMore($aEvent, $bPerform = false)
  1605. {
  1606. $oMoreMenu = $this->getManageMenuObject();
  1607. $oMoreMenu->setEventById($aEvent['id']);
  1608. return $oMoreMenu->isVisible();
  1609. }
  1610. public function checkAllowedView ($aContentInfo, $isPerformAction = false)
  1611. {
  1612. if(!$this->isAllowedView($aContentInfo, $isPerformAction))
  1613. return _t('_sys_txt_access_denied');
  1614. return CHECK_ACTION_RESULT_ALLOWED;
  1615. }
  1616. public function checkAllowedCommentsView ($aContentInfo, $isPerformAction = false)
  1617. {
  1618. $CNF = $this->_oConfig->CNF;
  1619. $mixedResult = BxDolProfile::getInstance($aContentInfo[$CNF['FIELD_OWNER_ID']])->checkAllowedProfileView();
  1620. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1621. return $mixedResult;
  1622. return CHECK_ACTION_RESULT_ALLOWED;
  1623. }
  1624. public function checkAllowedCommentsPost ($aContentInfo, $isPerformAction = false)
  1625. {
  1626. $sError = '_sys_txt_access_denied';
  1627. $aContentInfo = $this->_oTemplate->getData($aContentInfo);
  1628. if($aContentInfo === false)
  1629. return _t($sError);
  1630. if(!$this->isAllowedComment($aContentInfo, $isPerformAction))
  1631. return _t($sError);
  1632. return CHECK_ACTION_RESULT_ALLOWED;
  1633. }
  1634. public function onPost($iId)
  1635. {
  1636. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1637. if($this->_oConfig->isSystem($aEvent['type'], $aEvent['action'])) {
  1638. //--- Request event's data from content module and update it in the Timeline DB.
  1639. $this->_oTemplate->getData($aEvent);
  1640. $sPostType = 'system';
  1641. $iSenderId = $aEvent['owner_id'];
  1642. } else {
  1643. $sPostType = 'common';
  1644. $iSenderId = $aEvent['object_id'];
  1645. }
  1646. //--- Event -> Post for Alerts Engine ---//
  1647. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'post_' . $sPostType, $iId, $iSenderId, array(
  1648. 'privacy_view' => $aEvent['object_privacy_view'],
  1649. 'object_author_id' => $aEvent['owner_id'],
  1650. ));
  1651. $oAlert->alert();
  1652. //--- Event -> Post for Alerts Engine ---//
  1653. }
  1654. public function onRepost($iId, $aReposted = array())
  1655. {
  1656. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iId));
  1657. if(empty($aReposted)) {
  1658. $aContent = unserialize($aEvent['content']);
  1659. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  1660. if(empty($aReposted) || !is_array($aReposted))
  1661. return;
  1662. }
  1663. $iUserId = $this->getUserId();
  1664. $this->_oDb->insertRepostTrack($aEvent['id'], $iUserId, $this->getUserIp(), $aReposted['id']);
  1665. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts']);
  1666. //--- Timeline -> Update for Alerts Engine ---//
  1667. $oAlert = new BxDolAlerts($this->_oConfig->getObject('alert'), 'repost', $aReposted['id'], $iUserId, array(
  1668. 'privacy_view' => $aEvent['object_privacy_view'],
  1669. 'object_author_id' => $aReposted['owner_id'],
  1670. 'repost_id' => $iId,
  1671. ));
  1672. $oAlert->alert();
  1673. //--- Timeline -> Update for Alerts Engine ---//
  1674. }
  1675. public function onDelete($aEvent)
  1676. {
  1677. $iUserId = $this->getUserId();
  1678. $sCommonPostPrefix = $this->_oConfig->getPrefix('common_post');
  1679. $sCommonPostComment = $this->_oConfig->getObject('comment');
  1680. //--- Delete comments for Common posts.
  1681. if($this->_oConfig->isCommon($aEvent['type'], $aEvent['action'])) {
  1682. $oComments = $this->getCmtsObject($sCommonPostComment, $aEvent['id']);
  1683. if($oComments !== false)
  1684. $oComments->onObjectDelete($aEvent['id']);
  1685. }
  1686. //--- Delete attached photos, videos and links when common event was deleted.
  1687. if($aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_POST) {
  1688. $this->_deleteMedia(BX_TIMELINE_MEDIA_PHOTO, $aEvent['id']);
  1689. $this->_deleteMedia(BX_TIMELINE_MEDIA_VIDEO, $aEvent['id']);
  1690. $this->_deleteLinks($aEvent['id']);
  1691. }
  1692. //--- Update parent event when repost event was deleted.
  1693. $bRepost = $aEvent['type'] == $sCommonPostPrefix . BX_TIMELINE_PARSE_TYPE_REPOST;
  1694. if($bRepost) {
  1695. $this->_oDb->deleteRepostTrack($aEvent['id']);
  1696. $aContent = unserialize($aEvent['content']);
  1697. $aReposted = $this->_oDb->getReposted($aContent['type'], $aContent['action'], $aContent['object_id']);
  1698. if(!empty($aReposted) && is_array($aReposted))
  1699. $this->_oDb->updateRepostCounter($aReposted['id'], $aReposted['reposts'], -1);
  1700. }
  1701. //--- Find and delete repost events when parent event was deleted.
  1702. $bSystem = $this->_oConfig->isSystem($aEvent['type'], $aEvent['action']);
  1703. $aRepostEvents = $this->_oDb->getEvents(array('browse' => 'reposted_by_descriptor', 'type' => $aEvent['type']));
  1704. foreach($aRepostEvents as $aRepostEvent) {
  1705. $aContent = unserialize($aRepostEvent['content']);
  1706. 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) {
  1707. $oComments = $this->getCmtsObject($sCommonPostComment, $aRepostEvent['id']);
  1708. if($oComments !== false)
  1709. $oComments->onObjectDelete($aRepostEvent['id']);
  1710. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aEvent['id'], $iUserId, array(
  1711. 'repost_id' => $aRepostEvent['id'],
  1712. ));
  1713. }
  1714. }
  1715. //--- Delete associated meta.
  1716. $oMetatags = BxDolMetatags::getObjectInstance($this->_oConfig->getObject('metatags'));
  1717. $oMetatags->onDeleteContent($aEvent['id']);
  1718. //--- Event -> Delete for Alerts Engine ---//
  1719. if($bRepost)
  1720. bx_alert($this->_oConfig->getObject('alert'), 'delete_repost', $aReposted['id'], $iUserId, array(
  1721. 'repost_id' => $aEvent['id'],
  1722. ));
  1723. else
  1724. bx_alert($this->_oConfig->getObject('alert'), 'delete', $aEvent['id'], $iUserId);
  1725. //--- Event -> Delete for Alerts Engine ---//
  1726. }
  1727. public function getParams($sView = '', $sType = '', $iOwnerId = 0, $iStart = 0, $iPerPage = 0, $sFilter = '', $aModules = array(), $iTimeline = 0)
  1728. {
  1729. return $this->_prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1730. }
  1731. public function getViewsData(&$aViews)
  1732. {
  1733. if(empty($aViews) || !is_array($aViews))
  1734. return false;
  1735. $sSystem = isset($aViews['system']) ? $aViews['system'] : '';
  1736. $iObjectId = isset($aViews['object_id']) ? (int)$aViews['object_id'] : 0;
  1737. $iCount = isset($aViews['count']) ? (int)$aViews['count'] : 0;
  1738. if($sSystem == '' || $iObjectId == 0)
  1739. return false;
  1740. return array($sSystem, $iObjectId, $iCount);
  1741. }
  1742. public function getVotesData(&$aVotes)
  1743. {
  1744. if(empty($aVotes) || !is_array($aVotes))
  1745. return false;
  1746. $sSystem = isset($aVotes['system']) ? $aVotes['system'] : '';
  1747. $iObjectId = isset($aVotes['object_id']) ? (int)$aVotes['object_id'] : 0;
  1748. $iCount = isset($aVotes['count']) ? (int)$aVotes['count'] : 0;
  1749. if($sSystem == '' || $iObjectId == 0)
  1750. return false;
  1751. return array($sSystem, $iObjectId, $iCount);
  1752. }
  1753. public function getReportsData(&$aReports)
  1754. {
  1755. if(empty($aReports) || !is_array($aReports))
  1756. return false;
  1757. $sSystem = isset($aReports['system']) ? $aReports['system'] : '';
  1758. $iObjectId = isset($aReports['object_id']) ? (int)$aReports['object_id'] : 0;
  1759. $iCount = isset($aReports['count']) ? (int)$aReports['count'] : 0;
  1760. if($sSystem == '' || $iObjectId == 0)
  1761. return false;
  1762. return array($sSystem, $iObjectId, $iCount);
  1763. }
  1764. public function getCommentsData(&$aComments)
  1765. {
  1766. if(empty($aComments) || !is_array($aComments))
  1767. return false;
  1768. $sSystem = isset($aComments['system']) ? $aComments['system'] : '';
  1769. $iObjectId = isset($aComments['object_id']) ? (int)$aComments['object_id'] : 0;
  1770. $iCount = isset($aComments['count']) ? (int)$aComments['count'] : 0;
  1771. if($sSystem == '' || $iObjectId == 0 || ($iCount == 0 && !isLogged()))
  1772. return false;
  1773. return array($sSystem, $iObjectId, $iCount);
  1774. }
  1775. /**
  1776. * Protected Methods
  1777. */
  1778. protected function _serviceGetBlockView($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT)
  1779. {
  1780. if(empty($iProfileId) && bx_get('profile_id') !== false)
  1781. $iProfileId = bx_process_input(bx_get('profile_id'), BX_DATA_INT);
  1782. if(empty($iProfileId) && isLogged())
  1783. $iProfileId = bx_get_logged_profile_id();
  1784. $aBlock = $this->_getBlockView($iProfileId, $sView);
  1785. if(!empty($aBlock))
  1786. return $aBlock;
  1787. return array('content' => MsgBox(_t('_bx_timeline_txt_msg_no_results')));
  1788. }
  1789. protected function _serviceGetBlockViewProfile($sProfileModule = 'bx_persons', $iProfileContentId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1790. {
  1791. if(empty($sProfileModule))
  1792. return array();
  1793. if(empty($iProfileContentId) && bx_get('id') !== false)
  1794. $iProfileContentId = bx_process_input(bx_get('id'), BX_DATA_INT);
  1795. $oProfile = BxDolProfile::getInstanceByContentAndType($iProfileContentId, $sProfileModule);
  1796. if(empty($oProfile))
  1797. return array();
  1798. return $this->_getBlockView($oProfile->id(), $sView, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1799. }
  1800. protected function _serviceGetBlockViewHome($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1801. {
  1802. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_PUBLIC . '/';
  1803. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view_home'), $sRssUrl);
  1804. return $this->_serviceGetBlockViewByType($iProfileId, $sView, BX_BASE_MOD_NTFS_TYPE_PUBLIC, $iStart, $iPerPage, $this->_oConfig->getPerPage('home'), $iTimeline, $sFilter, $aModules);
  1805. }
  1806. protected function _serviceGetBlockViewByType($iProfileId = 0, $sView = BX_TIMELINE_VIEW_DEFAULT, $sType = BX_TIMELINE_TYPE_DEFAULT, $iStart = -1, $iPerPage = -1, $iPerPageDefault = -1, $iTimeline = -1, $sFilter = '', $aModules = array())
  1807. {
  1808. $aParams = $this->_prepareParams($sView, $sType, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1809. $aParams['view'] = $sView;
  1810. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : ((int)$iPerPageDefault > 0 ? $iPerPageDefault : $this->_oConfig->getPerPage());
  1811. $this->_iOwnerId = $aParams['owner_id'];
  1812. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1813. return array('content' => $sContent);
  1814. }
  1815. protected function _getBlockPost($iProfileId, $aParams = array())
  1816. {
  1817. $this->_iOwnerId = $iProfileId;
  1818. if($this->isAllowedPost() !== true)
  1819. return array();
  1820. $sContent = $this->_oTemplate->getPostBlock($this->_iOwnerId, $aParams);
  1821. return array('content' => $sContent);
  1822. }
  1823. protected function _getBlockView($iProfileId, $sView = BX_TIMELINE_VIEW_DEFAULT, $iStart = -1, $iPerPage = -1, $sFilter = '', $aModules = array(), $iTimeline = -1)
  1824. {
  1825. if(!$iProfileId)
  1826. return array();
  1827. $aParams = $this->_prepareParams($sView, BX_BASE_MOD_NTFS_TYPE_OWNER, $iProfileId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline);
  1828. $aParams['view'] = $sView;
  1829. $aParams['per_page'] = (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage('profile');
  1830. $this->_iOwnerId = $aParams['owner_id'];
  1831. $oProfileOwner = BxDolProfile::getInstance($this->_iOwnerId);
  1832. $mixedResult = $oProfileOwner->checkAllowedProfileView();
  1833. if($mixedResult !== CHECK_ACTION_RESULT_ALLOWED)
  1834. return array('content' => MsgBox($mixedResult));
  1835. list($sUserName, $sUserUrl) = $this->getUserInfo($aParams['owner_id']);
  1836. $sRssUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'rss/' . BX_BASE_MOD_NTFS_TYPE_OWNER . '/' . $iProfileId . '/';
  1837. $sJsObject = $this->_oConfig->getJsObject('view');
  1838. $aMenu = array(
  1839. 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),
  1840. 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)),
  1841. 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')),
  1842. array('id' => $sView . '-get-rss', 'name' => $sView . '-get-rss', 'class' => '', 'link' => $sRssUrl, 'target' => '_blank', 'title' => _t('_bx_timeline_menu_item_get_rss')),
  1843. );
  1844. $sContent = '';
  1845. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_view', $this->_iOwnerId, $this->getUserId(), array('override_content' => &$sContent, 'params' => &$aParams, 'menu' => &$aMenu));
  1846. $oMenu = new BxTemplMenuInteractive(array('template' => 'menu_interactive_vertical.html', 'menu_id'=> $sView . '-view-all', 'menu_items' => $aMenu));
  1847. $oMenu->setSelected('', $sView . '-view-all');
  1848. if (!$sContent)
  1849. $sContent = $this->_oTemplate->getViewBlock($aParams);
  1850. BxDolTemplate::getInstance()->addPageRssLink(_t('_bx_timeline_page_title_view'), $sRssUrl);
  1851. return array('content' => $sContent, 'menu' => $oMenu);
  1852. }
  1853. protected function _isAllowedPin($aEvent, $bPerform = false)
  1854. {
  1855. if(isAdmin())
  1856. return true;
  1857. $iUserId = (int)$this->getUserId();
  1858. if($iUserId == 0)
  1859. return false;
  1860. if((int)$aEvent['owner_id'] == $iUserId)
  1861. return true;
  1862. $aCheckResult = checkActionModule($iUserId, 'pin', $this->getName(), $bPerform);
  1863. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1864. if($oProfileOwner !== false)
  1865. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_pin', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1866. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1867. }
  1868. protected function _isAllowedPromote($aEvent, $bPerform = false)
  1869. {
  1870. if(isAdmin())
  1871. return true;
  1872. $iUserId = (int)$this->getUserId();
  1873. if($iUserId == 0)
  1874. return false;
  1875. $aCheckResult = checkActionModule($iUserId, 'promote', $this->getName(), $bPerform);
  1876. $oProfileOwner = BxDolProfile::getInstance($aEvent['owner_id']);
  1877. if($oProfileOwner !== false)
  1878. bx_alert($oProfileOwner->getModule(), $this->_oConfig->getUri() . '_promote', $oProfileOwner->id(), $iUserId, array('check_result' => &$aCheckResult));
  1879. return $aCheckResult[CHECK_ACTION_RESULT] !== CHECK_ACTION_RESULT_ALLOWED ? $aCheckResult[CHECK_ACTION_MESSAGE] : true;
  1880. }
  1881. protected function _addLink(&$oForm)
  1882. {
  1883. $iUserId = $this->getUserId();
  1884. $sLink = $oForm->getCleanValue('url');
  1885. $aMatches = array();
  1886. preg_match($this->_oConfig->getPregPattern('url'), $sLink, $aMatches);
  1887. $sLink = (empty($aMatches[2]) ? 'http://' : '') . $aMatches[0];
  1888. $aSiteInfo = bx_get_site_info($sLink, array(
  1889. 'thumbnailUrl' => array('tag' => 'link', 'content_attr' => 'href'),
  1890. 'OGImage' => array('name_attr' => 'property', 'name' => 'og:image'),
  1891. ));
  1892. $sTitle = !empty($aSiteInfo['title']) ? $aSiteInfo['title'] : _t('_Empty');
  1893. $sDescription = !empty($aSiteInfo['description']) ? $aSiteInfo['description'] : _t('_Empty');
  1894. $sMediaUrl = '';
  1895. if(!empty($aSiteInfo['thumbnailUrl']))
  1896. $sMediaUrl = $aSiteInfo['thumbnailUrl'];
  1897. else if(!empty($aSiteInfo['OGImage']))
  1898. $sMediaUrl = $aSiteInfo['OGImage'];
  1899. $iMediaId = 0;
  1900. $oStorage = null;
  1901. if(!empty($sMediaUrl)) {
  1902. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . BX_TIMELINE_MEDIA_PHOTO . 's'));
  1903. $iMediaId = $oStorage->storeFileFromUrl($sMediaUrl, true, $iUserId);
  1904. }
  1905. $iId = (int)$oForm->insert(array('profile_id' => $iUserId, 'media_id' => $iMediaId, 'url' => $sLink, 'title' => $sTitle, 'text' => $sDescription, 'added' => time()));
  1906. if(!empty($iId)) {
  1907. if(!empty($oStorage) && !empty($iMediaId))
  1908. $oStorage->afterUploadCleanup($iMediaId, $iUserId);
  1909. return array('id' => $iId, 'item' => $this->_oTemplate->getAttachLinkItem($iUserId, $iId));
  1910. }
  1911. return array('message' => _t('_bx_timeline_txt_err_cannot_perform_action'));
  1912. }
  1913. protected function _deleteLinks($iId)
  1914. {
  1915. $aLinks = $this->_oDb->getLinks($iId);
  1916. if(empty($aLinks) || !is_array($aLinks))
  1917. return;
  1918. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_photos'));
  1919. foreach($aLinks as $aLink)
  1920. if(!empty($aLink['media_id']))
  1921. $oStorage->deleteFile($aLink['media_id']);
  1922. $this->_oDb->deleteLinks($iId);
  1923. }
  1924. protected function _saveMedia($sType, $iId, $aItemIds)
  1925. {
  1926. if(empty($aItemIds) || !is_array($aItemIds))
  1927. return;
  1928. $iUserId = $this->getUserId();
  1929. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1930. foreach($aItemIds as $iItemId)
  1931. if($this->_oDb->saveMedia($sType, $iId, $iItemId))
  1932. $oStorage->afterUploadCleanup($iItemId, $iUserId);
  1933. }
  1934. protected function _deleteMedia($sType, $iId)
  1935. {
  1936. $aItems = $this->_oDb->getMedia($sType, $iId);
  1937. if(empty($aItems) || !is_array($aItems))
  1938. return;
  1939. $oStorage = BxDolStorage::getObjectInstance($this->_oConfig->getObject('storage_' . strtolower($sType) . 's'));
  1940. foreach($aItems as $iItemId)
  1941. $oStorage->deleteFile($iItemId);
  1942. $this->_oDb->deleteMedia($sType, $iId);
  1943. }
  1944. protected function _prepareParams($sView, $sType, $iOwnerId, $iStart, $iPerPage, $sFilter, $aModules, $iTimeline)
  1945. {
  1946. return array(
  1947. 'view' => !empty($sView) ? $sView : BX_TIMELINE_VIEW_DEFAULT,
  1948. 'browse' => 'list',
  1949. 'type' => !empty($sType) ? $sType : BX_TIMELINE_TYPE_DEFAULT,
  1950. 'owner_id' => (int)$iOwnerId != 0 ? $iOwnerId : $this->getUserId(),
  1951. 'filter' => !empty($sFilter) ? $sFilter : BX_TIMELINE_FILTER_ALL,
  1952. 'modules' => is_array($aModules) && !empty($aModules) ? $aModules : array(),
  1953. 'timeline' => (int)$iTimeline > 0 ? $iTimeline : 0,
  1954. 'active' => 1,
  1955. 'hidden' => 0,
  1956. 'start' => (int)$iStart > 0 ? $iStart : 0,
  1957. 'per_page' => (int)$iPerPage > 0 ? $iPerPage : $this->_oConfig->getPerPage(),
  1958. );
  1959. }
  1960. protected function _prepareParamsGet()
  1961. {
  1962. $aParams = array(
  1963. 'browse' => 'list',
  1964. 'dynamic_mode' => true,
  1965. );
  1966. $aParams['view'] = bx_get('view');
  1967. $aParams['view'] = $aParams['view'] !== false ? bx_process_input($aParams['view'], BX_DATA_TEXT) : BX_TIMELINE_VIEW_DEFAULT;
  1968. $aParams['type'] = bx_get('type');
  1969. $aParams['type'] = $aParams['type'] !== false ? bx_process_input($aParams['type'], BX_DATA_TEXT) : BX_TIMELINE_TYPE_DEFAULT;
  1970. $aParams['owner_id'] = bx_get('owner_id');
  1971. $aParams['owner_id'] = $aParams['owner_id'] !== false ? bx_process_input($aParams['owner_id'], BX_DATA_INT) : $this->getUserId();
  1972. $aParams['start'] = bx_get('start');
  1973. $aParams['start'] = $aParams['start'] !== false ? bx_process_input($aParams['start'], BX_DATA_INT) : 0;
  1974. $aParams['per_page'] = bx_get('per_page');
  1975. $aParams['per_page'] = $aParams['per_page'] !== false ? bx_process_input($aParams['per_page'], BX_DATA_INT) : $this->_oConfig->getPerPage();
  1976. $aParams['filter'] = bx_get('filter');
  1977. $aParams['filter'] = $aParams['filter'] !== false ? bx_process_input($aParams['filter'], BX_DATA_TEXT) : BX_TIMELINE_FILTER_ALL;
  1978. $aParams['modules'] = bx_get('modules');
  1979. $aParams['modules'] = $aParams['modules'] !== false ? bx_process_input($aParams['modules'], BX_DATA_TEXT) : array();
  1980. $aParams['timeline'] = bx_get('timeline');
  1981. $aParams['timeline'] = $aParams['timeline'] !== false ? bx_process_input($aParams['timeline'], BX_DATA_INT) : 0;
  1982. $aParams['active'] = 1;
  1983. $aParams['hidden'] = 0;
  1984. return $aParams;
  1985. }
  1986. protected function _prepareTextForSave($s)
  1987. {
  1988. return bx_process_input($s, BX_DATA_HTML);
  1989. }
  1990. protected function _getFieldValue($sField, $iContentId)
  1991. {
  1992. $CNF = &$this->_oConfig->CNF;
  1993. if(empty($CNF[$sField]))
  1994. return false;
  1995. $aEvent = $this->_oDb->getEvents(array('browse' => 'id', 'value' => $iContentId));
  1996. if(empty($aEvent) || empty($aEvent[$CNF[$sField]]))
  1997. return false;
  1998. return $aEvent[$CNF[$sField]];
  1999. }
  2000. }
  2001. /** @} */