BxDolTwigModule.php 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604
  1. <?php
  2. // TODO: decide later what to do with twig* classes and module, it looks like they will stay and 'complex' modules will be still based on it, but some refactoring is needed
  3. /***************************************************************************
  4. * Dolphin Smart Community Builder
  5. * -------------------
  6. * begin : Mon Mar 23 2006
  7. * copyright : (C) 2007 BoonEx Group
  8. * website : http://www.boonex.com
  9. * This file is part of Dolphin - Smart Community Builder
  10. *
  11. * Dolphin is free software; you can redistribute it and/or modify it under
  12. * the terms of the GNU General Public License as published by the
  13. * Free Software Foundation; either version 2 of the
  14. * License, or any later version.
  15. *
  16. * Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  17. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  18. * See the GNU General Public License for more details.
  19. * You should have received a copy of the GNU General Public License along with Dolphin,
  20. * see license.txt file; if not, write to marketing@boonex.com
  21. ***************************************************************************/
  22. bx_import ('BxDolModule');
  23. /**
  24. * Base module class for modules like events/groups/store
  25. */
  26. class BxDolTwigModule extends BxDolModule {
  27. var $_iAccountId;
  28. var $_oAccount;
  29. var $_iProfileId;
  30. var $_oProfile;
  31. var $_sPrefix;
  32. var $_sFilterName;
  33. function BxDolTwigModule(&$aModule) {
  34. parent::BxDolModule($aModule);
  35. bx_import('BxDolAccount');
  36. $this->_oAccount = BxDolAccount::getInstance();
  37. $this->_iAccountId = $this->_oAccount ? $this->_oAccount->id() : 0;
  38. bx_import('BxDolProfile');
  39. $this->_oProfile = BxDolProfile::getInstance();
  40. $this->_iProfileId = $this->_oProfile ? $this->_oProfile->id() : 0;
  41. }
  42. function _actionHome ($sPage, $sTitle) {
  43. $this->_oTemplate->pageStart();
  44. bx_import('BxDolPage');
  45. $oPage = BxDolPage::getObjectInstance($sPage);
  46. if (!$oPage) {
  47. $this->_oTemplate->displayPageNotFound();
  48. exit;
  49. }
  50. echo $oPage->getCode();
  51. $this->_oTemplate->addCss ('main.css');
  52. $this->_oTemplate->addCss ('unit.css');
  53. $this->_oTemplate->pageCode($sTitle, false, false);
  54. }
  55. function _actionFiles ($sUri, $sTitle) {
  56. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle)))
  57. return;
  58. $aRestriction = array (
  59. 'id' => $this->_oDb->getMediaIds($aDataEntry[$this->_oDb->_sFieldId], 'files'),
  60. );
  61. if (!$aRestriction['id']) {
  62. $this->_oTemplate->displayNoData ();
  63. return;
  64. }
  65. $this->_oTemplate->pageStart();
  66. echo BxDolService::call ('files', 'get_browse_block', array($aRestriction, $this->_oConfig->getBaseUri() . 'files/' . $sUri), 'Search');
  67. $this->_oTemplate->pageCode($sTitle);
  68. }
  69. function _actionVideos ($sUri, $sTitle) {
  70. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle)))
  71. return;
  72. $aRestriction = array (
  73. 'id' => $this->_oDb->getMediaIds($aDataEntry[$this->_oDb->_sFieldId], 'videos'),
  74. );
  75. if (!$aRestriction['id']) {
  76. $this->_oTemplate->displayNoData ();
  77. return;
  78. }
  79. $this->_oTemplate->pageStart();
  80. echo BxDolService::call ('videos', 'get_browse_block', array($aRestriction, $this->_oConfig->getBaseUri() . 'videos/' . $sUri), 'Search');
  81. $this->_oTemplate->pageCode($sTitle);
  82. }
  83. function _actionSounds ($sUri, $sTitle) {
  84. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle)))
  85. return;
  86. $aRestriction = array (
  87. 'id' => $this->_oDb->getMediaIds($aDataEntry[$this->_oDb->_sFieldId], 'sounds'),
  88. );
  89. if (!$aRestriction['id']) {
  90. $this->_oTemplate->displayNoData ();
  91. return;
  92. }
  93. $this->_oTemplate->pageStart();
  94. echo BxDolService::call ('sounds', 'get_browse_block', array($aRestriction, $this->_oConfig->getBaseUri() . 'sounds/' . $sUri), 'Search');
  95. $this->_oTemplate->pageCode($sTitle);
  96. }
  97. function _actionPhotos ($sUri, $sTitle) {
  98. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle)))
  99. return;
  100. $aRestriction = array (
  101. 'id' => $this->_oDb->getMediaIds($aDataEntry[$this->_oDb->_sFieldId], 'images'),
  102. );
  103. if (!$aRestriction['id']) {
  104. $this->_oTemplate->displayNoData ();
  105. return;
  106. }
  107. $this->_oTemplate->pageStart();
  108. echo BxDolService::call ('photos', 'get_browse_block', array($aRestriction, $this->_oConfig->getBaseUri() . 'photos/' . $sUri), 'Search');
  109. $this->_oTemplate->pageCode($sTitle);
  110. }
  111. function _actionComments ($sUri, $sTitle) {
  112. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle)))
  113. return;
  114. bx_import('Cmts', $this->_aModule);
  115. $sClass = $this->_aModule['class_prefix'] . 'Cmts';
  116. $o = new $sClass ($this->_sPrefix, (int)$aDataEntry[$this->_oDb->_sFieldId]);
  117. if (!$o->isEnabled()) {
  118. $this->_oTemplate->displayPageNotFound ();
  119. return;
  120. }
  121. $sRet = $o->getCommentsFirst ();
  122. $this->_oTemplate->pageStart();
  123. echo DesignBoxContent ($sTitle, $sRet, 1);
  124. $this->_oTemplate->pageCode($sTitle, 0, 0);
  125. }
  126. function _actionBrowseFans ($sUri, $sFuncAllowed, $sFuncDbGetFans, $iPerPage, $sUrlBrowse, $sTitle) {
  127. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle))) {
  128. return;
  129. }
  130. if (!$this->$sFuncAllowed($aDataEntry)) {
  131. $this->_oTemplate->displayAccessDenied ();
  132. return;
  133. }
  134. $iPage = (int)$_GET['page'];
  135. if( $iPage < 1)
  136. $iPage = 1;
  137. $iStart = ($iPage - 1) * $iPerPage;
  138. $aProfiles = array ();
  139. $iNum = $this->_oDb->$sFuncDbGetFans($aProfiles, $aDataEntry[$this->_oDb->_sFieldId], $iStart, $iPerPage);
  140. if (!$iNum || !$aProfiles) {
  141. $this->_oTemplate->displayNoData ();
  142. return;
  143. }
  144. $iPages = ceil($iNum / $iPerPage);
  145. bx_import('BxTemplSearchProfile');
  146. $oBxTemplSearchProfile = new BxTemplSearchProfile();
  147. $sMainContent = '';
  148. foreach ($aProfiles as $aProfile) {
  149. $sMainContent .= $oBxTemplSearchProfile->displaySearchUnit($aProfile);
  150. }
  151. $sRet = $GLOBALS['oFunctions']->centerContent($sMainContent, '.searchrow_block_simple');
  152. $sRet .= '<div class="clear_both"></div>';
  153. bx_import('BxDolPaginate');
  154. $sUrlStart = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . $sUrlBrowse . $aDataEntry[$this->_oDb->_sFieldUri];
  155. $sUrlStart .= (false === strpos($sUrlStart, '?') ? '?' : '&');
  156. $oPaginate = new BxDolPaginate(array(
  157. 'page_url' => $sUrlStart . 'page={page}&per_page={per_page}' . (false !== bx_get($this->sFilterName) ? '&' . $this->sFilterName . '=' . bx_get($this->sFilterName) : ''),
  158. 'count' => $iNum,
  159. 'per_page' => $iPerPage,
  160. 'page' => $iPage,
  161. 'per_page_changer' => false,
  162. 'page_reloader' => true,
  163. 'on_change_page' => '',
  164. 'on_change_per_page' => "document.location='" . $sUrlStart . "page=1&per_page=' + this.value + '" . (false !== bx_get($this->sFilterName) ? '&' . $this->sFilterName . '=' . bx_get($this->sFilterName) ."';": "';"),
  165. ));
  166. $sRet .= $oPaginate->getPaginate();
  167. $this->_oTemplate->pageStart();
  168. echo DesignBoxContent ($sTitle, $sRet, 1);
  169. $this->_oTemplate->pageCode($sTitle, false, false);
  170. }
  171. function _actionView ($sUri, $sPage, $sMsgPendingApproval) {
  172. if (!($aDataEntry = $this->_preProductTabs($sUri)))
  173. return;
  174. $this->_oTemplate->pageStart();
  175. bx_import('BxDolPage');
  176. $oPage = BxDolPage::getObjectInstance($sPage);
  177. if (!$oPage) {
  178. $this->_oTemplate->displayPageNotFound();
  179. exit;
  180. }
  181. $oPage->initWithUri($sUri);
  182. echo $oPage->getCode();
  183. /*
  184. if ($aDataEntry[$this->_oDb->_sFieldStatus] == 'pending') {
  185. $aVars = array ('msg' => $sMsgPendingApproval); // this product is pending approval, please wait until it will be activated
  186. echo $this->_oTemplate->parseHtmlByName ('pending_approval_plank', $aVars);
  187. }
  188. */
  189. // $this->_oTemplate->setPageDescription (substr(strip_tags($aDataEntry[$this->_oDb->_sFieldDescription]), 0, 255));
  190. // $this->_oTemplate->addPageKeywords ($aDataEntry[$this->_oDb->_sFieldTags]);
  191. $this->_oTemplate->addCss ('view.css');
  192. $this->_oTemplate->addCss ('main.css');
  193. $this->_oTemplate->addCss ('entry_view.css');
  194. $this->_oTemplate->pageCode($aDataEntry[$this->_oDb->_sFieldTitle], false, false);
  195. bx_import ('BxDolViews');
  196. new BxDolViews($this->_sPrefix, $aDataEntry[$this->_oDb->_sFieldId]);
  197. }
  198. function _actionUploadMedia ($sUri, $sIsAllowedFuncName, $sMedia, $aMediaFields, $sTitle) {
  199. if (!($aDataEntry = $this->_preProductTabs($sUri, $sTitle)))
  200. return;
  201. if (!$this->$sIsAllowedFuncName($aDataEntry)) {
  202. $this->_oTemplate->displayAccessDenied ();
  203. return;
  204. }
  205. $this->_oTemplate->pageStart();
  206. $iEntryId = $aDataEntry[$this->_oDb->_sFieldId];
  207. bx_import ('FormUploadMedia', $this->_aModule);
  208. $sClass = $this->_aModule['class_prefix'] . 'FormUploadMedia';
  209. $oForm = new $sClass ($this, $aDataEntry[$this->_oDb->_sFieldAuthorId], $iEntryId, $aDataEntry, $sMedia, $aMediaFields);
  210. $oForm->initChecker($aDataEntry);
  211. if ($oForm->isSubmittedAndValid ()) {
  212. $this->$sIsAllowedFuncName($aDataEntry, true); // perform action
  213. header ('Location:' . BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri]);
  214. exit;
  215. } else {
  216. echo $oForm->getCode ();
  217. }
  218. $this->_oTemplate->addCss ('main.css');
  219. $this->_oTemplate->addCss ('forms_extra.css');
  220. $this->_oTemplate->pageCode($sTitle);
  221. }
  222. function _actionBroadcast ($iEntryId, $sTitle, $sMsgNoRecipients, $sMsgSent) {
  223. $iEntryId = (int)$iEntryId;
  224. if (!($aDataEntry = $this->_oDb->getEntryById($iEntryId))) {
  225. $this->_oTemplate->displayPageNotFound ();
  226. return;
  227. }
  228. if (!$this->isAllowedBroadcast($aDataEntry)) {
  229. $this->_oTemplate->displayAccessDenied ();
  230. return;
  231. }
  232. $this->_oTemplate->pageStart();
  233. $GLOBALS['oTopMenu']->setCustomSubHeader($aDataEntry[$this->_oDb->_sFieldTitle]);
  234. $GLOBALS['oTopMenu']->setCustomVar($this->_sPrefix.'_view_uri', $aDataEntry[$this->_oDb->_sFieldUri]);
  235. $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
  236. _t('_'.$this->_sPrefix) => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'home/',
  237. $aDataEntry[$this->_oDb->_sFieldTitle] => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  238. $sTitle => '',
  239. ));
  240. $aRecipients = $this->_oDb->getBroadcastRecipients ($iEntryId);
  241. if (!$aRecipients) {
  242. echo MsgBox ($sMsgNoRecipients);
  243. $this->_oTemplate->pageCode($sMsgNoRecipients, true, true);
  244. return;
  245. }
  246. bx_import ('FormBroadcast', $this->_aModule);
  247. $sClass = $this->_aModule['class_prefix'] . 'FormBroadcast';
  248. $oForm = new $sClass ();
  249. $oForm->initChecker();
  250. if ($oForm->isSubmittedAndValid ()) {
  251. $oEmailTemplate = new BxDolEmailTemplates();
  252. if (!$oEmailTemplate) {
  253. $this->_oTemplate->displayErrorOccured();
  254. return;
  255. }
  256. $aTemplate = $oEmailTemplate->getTemplate($this->_sPrefix . '_broadcast');
  257. $aTemplateVars = array (
  258. 'BroadcastTitle' => $this->_oDb->unescape($oForm->getCleanValue ('title')),
  259. 'BroadcastMessage' => nl2br($this->_oDb->unescape($oForm->getCleanValue ('message'))),
  260. 'EntryTitle' => $aDataEntry[$this->_oDb->_sFieldTitle],
  261. 'EntryUrl' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  262. );
  263. $iSentMailsCounter = 0;
  264. foreach ($aRecipients as $aProfile) {
  265. $iSentMailsCounter += sendMail($aProfile['Email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['ID'], $aTemplateVars);
  266. }
  267. if (!$iSentMailsCounter) {
  268. $this->_oTemplate->displayErrorOccured();
  269. return;
  270. }
  271. echo MsgBox ($sMsgSent);
  272. $this->isAllowedBroadcast($aDataEntry, true); // perform send broadcast message action
  273. $this->_oTemplate->addCss ('main.css');
  274. $this->_oTemplate->pageCode($sMsgSent, true, true);
  275. return;
  276. }
  277. echo $oForm->getCode ();
  278. $this->_oTemplate->addCss ('main.css');
  279. $this->_oTemplate->pageCode($sTitle);
  280. }
  281. function _getInviteParams ($aDataEntry, $aInviter) {
  282. // override this
  283. return array ();
  284. }
  285. function _actionInvite ($iEntryId, $sEmailTemplate, $iMaxEmailInvitations, $sMsgInvitationSent, $sMsgNoUsers, $sTitle) {
  286. $iEntryId = (int)$iEntryId;
  287. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner($iEntryId, $this->_iProfileId, $this->isAdmin()))) {
  288. $this->_oTemplate->displayPageNotFound ();
  289. return;
  290. }
  291. $this->_oTemplate->pageStart();
  292. $GLOBALS['oTopMenu']->setCustomSubHeader($aDataEntry[$this->_oDb->_sFieldTitle]);
  293. $GLOBALS['oTopMenu']->setCustomVar($this->_sPrefix.'_view_uri', $aDataEntry[$this->_oDb->_sFieldUri]);
  294. $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
  295. _t('_'.$this->_sPrefix) => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'home/',
  296. $aDataEntry[$this->_oDb->_sFieldTitle] => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  297. $sTitle . $aDataEntry[$this->_oDb->_sFieldTitle] => '',
  298. ));
  299. bx_import('BxDolTwigFormInviter');
  300. $oForm = new BxDolTwigFormInviter ($this, $sMsgNoUsers);
  301. $oForm->initChecker();
  302. if ($oForm->isSubmittedAndValid ()) {
  303. $aInviter = getProfileInfo($this->_iProfileId);
  304. $aPlusOriginal = $this->_getInviteParams ($aDataEntry, $aInviter);
  305. $oEmailTemplate = new BxDolEmailTemplates();
  306. $aTemplate = $oEmailTemplate->getTemplate($sEmailTemplate);
  307. $iSuccess = 0;
  308. // send invitation to registered members
  309. if (false !== bx_get('inviter_users') && is_array(bx_get('inviter_users'))) {
  310. $aInviteUsers = bx_get('inviter_users');
  311. foreach ($aInviteUsers as $iRecipient) {
  312. $aRecipient = getProfileInfo($iRecipient);
  313. $aPlus = array_merge (array ('NickName' => ' ' . getNickName($aRecipient['ID'])), $aPlusOriginal);
  314. $iSuccess += sendMail(trim($aRecipient['Email']), $aTemplate['Subject'], $aTemplate['Body'], '', $aPlus) ? 1 : 0;
  315. }
  316. }
  317. // send invitation to additional emails
  318. $iMaxCount = $iMaxEmailInvitations;
  319. $aEmails = preg_split ("#[,\s\\b]+#", bx_get('inviter_emails'));
  320. $aPlus = array_merge (array ('NickName' => ''), $aPlusOriginal);
  321. if ($aEmails && is_array($aEmails)) {
  322. foreach ($aEmails as $sEmail) {
  323. if (strlen($sEmail) < 5)
  324. continue;
  325. $iRet = sendMail(trim($sEmail), $aTemplate['Subject'], $aTemplate['Body'], '', $aPlus) ? 1 : 0;
  326. $iSuccess += $iRet;
  327. if ($iRet && 0 == --$iMaxCount)
  328. break;
  329. }
  330. }
  331. $sMsg = sprintf($sMsgInvitationSent, $iSuccess);
  332. echo MsgBox($sMsg);
  333. $this->_oTemplate->addCss ('main.css');
  334. $this->_oTemplate->pageCode ($sMsg, true, false);
  335. return;
  336. }
  337. echo $oForm->getCode ();
  338. $this->_oTemplate->addCss ('main.css');
  339. $this->_oTemplate->addCss ('inviter.css');
  340. $this->_oTemplate->pageCode($sTitle . $aDataEntry[$this->_oDb->_sFieldTitle]);
  341. }
  342. function _actionCalendar ($iYear, $iMonth, $sTitle) {
  343. $iYear = (int)$iYear;
  344. $iMonth = (int)$iMonth;
  345. if (!$this->isAllowedBrowse()) {
  346. $this->_oTemplate->displayAccessDenied ();
  347. return;
  348. }
  349. $this->_oTemplate->pageStart();
  350. bx_import ('Calendar', $this->_aModule);
  351. $oCalendar = bx_instance ($this->_aModule['class_prefix'] . 'Calendar', array ($iYear, $iMonth, $this->_oDb, $this->_oTemplate, $this->_oConfig));
  352. echo $oCalendar->display();
  353. $this->_oTemplate->addCss ('main.css');
  354. $this->_oTemplate->pageCode($sTitle . $oCalendar->getTitle(), true, false);
  355. }
  356. function actionBrowse ($sMode = '', $sValue = '', $sValue2 = '', $sValue3 = '') {
  357. if ('user' == $sMode || 'my' == $sMode) {
  358. $aProfile = getProfileInfo ($this->_iProfileId);
  359. if (0 == strcasecmp($sValue, $aProfile['NickName']) || 'my' == $sMode) {
  360. $this->_browseMy ($aProfile);
  361. return;
  362. }
  363. }
  364. if (!$this->isAllowedBrowse()) {
  365. $this->_oTemplate->displayAccessDenied ();
  366. return;
  367. }
  368. if ('tag' == $sMode || 'category' == $sMode)
  369. $sValue = uri2title($sValue);
  370. bx_import ('SearchResult', $this->_aModule);
  371. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  372. $o = new $sClass(bx_process_input($sMode), bx_process_input($sValue), bx_process_input($sValue2), bx_process_input($sValue3));
  373. if ($o->isError) {
  374. $this->_oTemplate->displayPageNotFound ();
  375. return;
  376. }
  377. if (bx_get('rss')) {
  378. echo $o->rss();
  379. exit;
  380. }
  381. $this->_oTemplate->pageStart();
  382. if ($s = $o->processing()) {
  383. echo $s;
  384. } else {
  385. $this->_oTemplate->displayNoData ();
  386. return;
  387. }
  388. $this->_oTemplate->addCss ('unit.css');
  389. $this->_oTemplate->addCss ('main.css');
  390. $this->_oTemplate->pageCode($o->aCurrent['title'], false, false);
  391. }
  392. function _actionSearch ($sKeyword, $sCategory, $sTitle) {
  393. if (!$this->isAllowedSearch()) {
  394. $this->_oTemplate->displayAccessDenied ();
  395. return;
  396. }
  397. $this->_oTemplate->pageStart();
  398. if ($sKeyword)
  399. $_GET['Keyword'] = $sKeyword;
  400. if ($sCategory)
  401. $_GET['Category'] = explode(',', $sCategory);
  402. if (is_array($_GET['Category']) && 1 == count($_GET['Category']) && !$_GET['Category'][0]) {
  403. unset($_GET['Category']);
  404. unset($sCategory);
  405. }
  406. if ($sCategory || $sKeyword) {
  407. $_GET['submit_form'] = 1;
  408. }
  409. bx_import ('FormSearch', $this->_aModule);
  410. $sClass = $this->_aModule['class_prefix'] . 'FormSearch';
  411. $oForm = new $sClass ();
  412. $oForm->initChecker();
  413. if ($oForm->isSubmittedAndValid ()) {
  414. bx_import ('SearchResult', $this->_aModule);
  415. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  416. $o = new $sClass('search', $oForm->getCleanValue('Keyword'), $oForm->getCleanValue('Category'));
  417. if ($o->isError) {
  418. $this->_oTemplate->displayPageNotFound ();
  419. return;
  420. }
  421. if ($s = $o->processing()) {
  422. echo $s;
  423. } else {
  424. $this->_oTemplate->displayNoData ();
  425. return;
  426. }
  427. $this->isAllowedSearch(true); // perform search action
  428. $this->_oTemplate->addCss ('unit.css');
  429. $this->_oTemplate->addCss ('main.css');
  430. $this->_oTemplate->pageCode($o->aCurrent['title'], false, false);
  431. } else {
  432. echo $oForm->getCode ();
  433. $this->_oTemplate->addCss ('main.css');
  434. $this->_oTemplate->pageCode($sTitle);
  435. }
  436. }
  437. function _actionAdd ($sTitle) {
  438. if (!$this->isAllowedAdd()) {
  439. $this->_oTemplate->displayAccessDenied ();
  440. return;
  441. }
  442. $this->_oTemplate->pageStart();
  443. $this->_addForm(false);
  444. $this->_oTemplate->addJs ('main.js');
  445. $this->_oTemplate->addCss ('main.css');
  446. $this->_oTemplate->addCss ('forms_extra.css');
  447. $this->_oTemplate->pageCode($sTitle);
  448. }
  449. function _actionEdit ($iEntryId, $sTitle) {
  450. $iEntryId = (int)$iEntryId;
  451. if (!($aDataEntry = $this->_oDb->getEntryById($iEntryId))) {
  452. $this->_oTemplate->displayPageNotFound ();
  453. return;
  454. }
  455. /*
  456. $GLOBALS['oTopMenu']->setCustomSubHeader($aDataEntry[$this->_oDb->_sFieldTitle]);
  457. $GLOBALS['oTopMenu']->setCustomVar($this->_sPrefix.'_view_uri', $aDataEntry[$this->_oDb->_sFieldUri]);
  458. $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
  459. _t('_'.$this->_sPrefix) => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'home/',
  460. $aDataEntry[$this->_oDb->_sFieldTitle] => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  461. $sTitle => '',
  462. ));
  463. */
  464. if (!$this->isAllowedEdit($aDataEntry)) {
  465. $this->_oTemplate->displayAccessDenied ();
  466. return;
  467. }
  468. $this->_oTemplate->pageStart();
  469. bx_import ('FormEdit', $this->_aModule);
  470. $sClass = $this->_aModule['class_prefix'] . 'FormEdit';
  471. $oForm = new $sClass ($this, $aDataEntry[$this->_oDb->_sFieldAuthorId], $iEntryId, $aDataEntry);
  472. if (isset($aDataEntry[$this->_oDb->_sFieldJoinConfirmation]))
  473. $aDataEntry[$this->_oDb->_sFieldJoinConfirmation] = (int)$aDataEntry[$this->_oDb->_sFieldJoinConfirmation];
  474. $oForm->initChecker($aDataEntry);
  475. if ($oForm->isSubmittedAndValid ()) {
  476. $sStatus = $this->_oDb->getParam($this->_sPrefix . '_autoapproval') == 'on' || $this->isAdmin() ? 'approved' : 'pending';
  477. $aValsAdd = array ($this->_oDb->_sFieldStatus => $sStatus);
  478. if ($oForm->update ($iEntryId, $aValsAdd)) {
  479. $this->isAllowedEdit($aDataEntry, true); // perform action
  480. $this->onEventChanged ($iEntryId, $sStatus);
  481. header ('Location:' . BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri]);
  482. exit;
  483. } else {
  484. echo MsgBox(_t('_Error Occured'));
  485. }
  486. } else {
  487. echo $oForm->getCode ();
  488. }
  489. $this->_oTemplate->addJs ('main.js');
  490. $this->_oTemplate->addCss ('main.css');
  491. $this->_oTemplate->addCss ('forms_extra.css');
  492. $this->_oTemplate->pageCode($sTitle);
  493. }
  494. function _actionDelete ($iEntryId, $sMsgSuccess) {
  495. header('Content-type:text/html;charset=utf-8');
  496. $iEntryId = (int)$iEntryId;
  497. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner($iEntryId, $this->_iProfileId, $this->isAdmin()))) {
  498. echo MsgBox(_t('_sys_request_page_not_found_cpt')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  499. exit;
  500. }
  501. if (!$this->isAllowedDelete($aDataEntry) || 0 != strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
  502. echo MsgBox(_t('_Access denied')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  503. exit;
  504. }
  505. if ($this->_oDb->deleteEntryByIdAndOwner($iEntryId, $this->_iProfileId, $this->isAdmin())) {
  506. $this->isAllowedDelete($aDataEntry, true); // perform action
  507. $this->onEventDeleted ($iEntryId, $aDataEntry);
  508. $sRedirect = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'browse/' . ($this->_iProfileId ? 'user/' . $this->_oDb->getProfileNickNameById($this->_iProfileId) : '');
  509. $sJQueryJS = genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div', $sRedirect);
  510. echo MsgBox(_t($sMsgSuccess)) . $sJQueryJS;
  511. exit;
  512. }
  513. echo MsgBox(_t('_Error Occured')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  514. exit;
  515. }
  516. function _actionMarkFeatured ($iEntryId, $sMsgSuccessAdd, $sMsgSuccessRemove) {
  517. header('Content-type:text/html;charset=utf-8');
  518. $iEntryId = (int)$iEntryId;
  519. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner($iEntryId, $this->_iProfileId, $this->isAdmin()))) {
  520. echo MsgBox(_t('_sys_request_page_not_found_cpt')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  521. exit;
  522. }
  523. if (!$this->isAllowedMarkAsFeatured($aDataEntry) || 0 != strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
  524. echo MsgBox(_t('_Access denied')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  525. exit;
  526. }
  527. if ($this->_oDb->markAsFeatured($iEntryId)) {
  528. $this->isAllowedMarkAsFeatured($aDataEntry, true); // perform action
  529. $this->onEventMarkAsFeatured ($iEntryId, $aDataEntry);
  530. $sRedirect = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri];
  531. $sJQueryJS = genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div', $sRedirect);
  532. echo MsgBox($aDataEntry[$this->_oDb->_sFieldFeatured] ? $sMsgSuccessRemove : $sMsgSuccessAdd) . $sJQueryJS;
  533. exit;
  534. }
  535. echo MsgBox(_t('_Error Occured')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  536. exit;
  537. }
  538. function _actionJoin ($iEntryId, $iProfileId, $sMsgAlreadyJoined, $sMsgAlreadyJoinedPending, $sMsgJoinSuccess, $sMsgJoinSuccessPending, $sMsgLeaveSuccess) {
  539. header('Content-type:text/html;charset=utf-8');
  540. $iEntryId = (int)$iEntryId;
  541. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner($iEntryId, 0, true))) {
  542. echo MsgBox(_t('_sys_request_page_not_found_cpt')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  543. exit;
  544. }
  545. if (!$this->isAllowedJoin($aDataEntry) || 0 != strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
  546. echo MsgBox(_t('_Access denied')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  547. exit;
  548. }
  549. $isFan = $this->_oDb->isFan ($iEntryId, $this->_iProfileId, true) || $this->_oDb->isFan ($iEntryId, $this->_iProfileId, false);
  550. if ($isFan) {
  551. if ($this->_oDb->leaveEntry($iEntryId, $this->_iProfileId)) {
  552. $sRedirect = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri];
  553. echo MsgBox($sMsgLeaveSuccess) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div', $sRedirect);
  554. exit;
  555. }
  556. } else {
  557. $isConfirmed = ($this->isEntryAdmin($aDataEntry) || !$aDataEntry[$this->_oDb->_sFieldJoinConfirmation] ? true : false);
  558. if ($this->_oDb->joinEntry($iEntryId, $this->_iProfileId, $isConfirmed)) {
  559. if ($isConfirmed) {
  560. $this->onEventJoin ($iEntryId, $this->_iProfileId, $aDataEntry);
  561. $sRedirect = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri];
  562. } else {
  563. $this->onEventJoinRequest ($iEntryId, $this->_iProfileId, $aDataEntry);
  564. $sRedirect = '';
  565. }
  566. echo MsgBox($isConfirmed ? $sMsgJoinSuccess : $sMsgJoinSuccessPending) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div', $sRedirect);
  567. exit;
  568. }
  569. }
  570. echo MsgBox(_t('_Error Occured')) . genAjaxyPopupJS($iEntryId, 'ajaxy_popup_result_div');
  571. exit;
  572. }
  573. function _actionManageFansPopup ($iEntryId, $sTitle, $sFuncGetFans = 'getFans', $sFuncIsAllowedManageFans = 'isAllowedManageFans', $sFuncIsAllowedManageAdmins = 'isAllowedManageAdmins', $iMaxFans = 1000) {
  574. header('Content-type:text/html;charset=utf-8');
  575. $iEntryId = (int)$iEntryId;
  576. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner ($iEntryId, 0, true))) {
  577. echo $GLOBALS['oFunctions']->transBox(MsgBox(_t('_Empty')));
  578. exit;
  579. }
  580. if (!$this->$sFuncIsAllowedManageFans($aDataEntry)) {
  581. echo $GLOBALS['oFunctions']->transBox(MsgBox(_t('_Access denied')));
  582. exit;
  583. }
  584. $aProfiles = array ();
  585. $iNum = $this->_oDb->$sFuncGetFans($aProfiles, $iEntryId, true, 0, $iMaxFans);
  586. if (!$iNum) {
  587. echo $GLOBALS['oFunctions']->transBox(MsgBox(_t('_Empty')));
  588. exit;
  589. }
  590. $sActionsUrl = bx_append_url_params(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . "view/" . $aDataEntry[$this->_oDb->_sFieldUri], 'ajax_action=');
  591. $aButtons = array (
  592. array (
  593. 'type' => 'submit',
  594. 'name' => 'fans_remove',
  595. 'value' => _t('_sys_btn_fans_remove'),
  596. 'onclick' => "onclick=\"getHtmlData('sys_manage_items_manage_fans_content', '{$sActionsUrl}remove&ids=' + sys_manage_items_get_manage_fans_ids(), false, 'post'); return false;\"",
  597. ),
  598. );
  599. if ($this->$sFuncIsAllowedManageAdmins($aDataEntry)) {
  600. $aButtons = array_merge($aButtons, array (
  601. array (
  602. 'type' => 'submit',
  603. 'name' => 'fans_add_to_admins',
  604. 'value' => _t('_sys_btn_fans_add_to_admins'),
  605. 'onclick' => "onclick=\"getHtmlData('sys_manage_items_manage_fans_content', '{$sActionsUrl}add_to_admins&ids=' + sys_manage_items_get_manage_fans_ids(), false, 'post'); return false;\"",
  606. ),
  607. array (
  608. 'type' => 'submit',
  609. 'name' => 'fans_move_admins_to_fans',
  610. 'value' => _t('_sys_btn_fans_move_admins_to_fans'),
  611. 'onclick' => "onclick=\"getHtmlData('sys_manage_items_manage_fans_content', '{$sActionsUrl}admins_to_fans&ids=' + sys_manage_items_get_manage_fans_ids(), false, 'post'); return false;\"",
  612. ),
  613. ));
  614. };
  615. bx_import ('BxTemplSearchResult');
  616. $sControl = BxTemplSearchResult::showAdminActionsPanel('sys_manage_items_manage_fans', $aButtons, 'sys_fan_unit');
  617. $aVarsContent = array (
  618. 'suffix' => 'manage_fans',
  619. 'content' => $this->_profilesEdit($aProfiles, false, $aDataEntry),
  620. 'control' => $sControl,
  621. );
  622. $aVarsPopup = array (
  623. 'title' => $sTitle,
  624. 'content' => $this->_oTemplate->parseHtmlByName('manage_items_form', $aVarsContent),
  625. );
  626. echo $GLOBALS['oFunctions']->transBox($this->_oTemplate->parseHtmlByName('popup', $aVarsPopup), true);
  627. exit;
  628. }
  629. function _actionSharePopup ($iEntryId, $sTitle, $bAddTempleateExt = false) {
  630. header('Content-type:text/html;charset=utf-8');
  631. $iEntryId = (int)$iEntryId;
  632. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner ($iEntryId, 0, true))) {
  633. echo MsgBox(_t('_Empty'));
  634. exit;
  635. }
  636. $sEntryUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri];
  637. require_once (BX_DIRECTORY_PATH_INC . "shared_sites.inc.php");
  638. echo getSitesHtml($sEntryUrl, $sTitle);
  639. exit;
  640. }
  641. function _actionTags($sTitle, $sTitleAllTags = '')
  642. {
  643. bx_import('BxTemplTagsModule');
  644. $aParam = array(
  645. 'type' => $this->_sPrefix,
  646. 'orderby' => 'popular'
  647. );
  648. $oTags = new BxTemplTagsModule($aParam, $sTitleAllTags, BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'tags');
  649. $this->_oTemplate->pageStart();
  650. echo $oTags->getCode();
  651. $this->_oTemplate->pageCode($sTitle, false, false);
  652. }
  653. function _actionCategories($sTitle)
  654. {
  655. bx_import('BxTemplCategoriesModule');
  656. $aParam = array(
  657. 'type' => $this->_sPrefix
  658. );
  659. $oCateg = new BxTemplCategoriesModule($aParam, _t('_categ_users'), BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'categories');
  660. $this->_oTemplate->pageStart();
  661. echo $oCateg->getCode();
  662. $this->_oTemplate->pageCode($sTitle, false, false);
  663. }
  664. function _actionDownload ($aFileInfo, $sFieldMediaId) {
  665. $aFile = BxDolService::call('files', 'get_file_array', array($aFileInfo[$sFieldMediaId]), 'Search');
  666. if (!$aFile['date']) {
  667. $this->_oTemplate->displayPageNotFound ();
  668. exit;
  669. }
  670. $aFile['full_name'] = uriFilter($aFile['title']) . '.' . $aFile['extension'];
  671. $aPathInfo = pathinfo ($aFile['path']);
  672. header ("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  673. header ("Content-type: " . $aFile['mime_type']);
  674. header ("Content-Length: " . filesize ($aFile['path']));
  675. header ("Content-Disposition: attachment; filename={$aFile['full_name']}");
  676. readfile ($aFile['path']);
  677. exit;
  678. }
  679. // ================================== external actions
  680. /**
  681. * Profile block with groups user joied
  682. * @param $iProfileId profile id
  683. * @return html to display on homepage in a block
  684. */
  685. function serviceContentInfo ($sUri) {
  686. if (!($aDataEntry = $this->_preProductTabs($sUri)))
  687. return;
  688. return '<pre>' . print_r($aDataEntry, 1) . '</pre>';
  689. }
  690. function serviceDeleteProfileData ($iProfileId) {
  691. $iProfileId = (int)$iProfileId;
  692. if (!$iProfileId)
  693. return false;
  694. // delete entries which belongs to particular author
  695. $aDataEntries = $this->_oDb->getEntriesByAuthor ($iProfileId);
  696. foreach ($aDataEntries as $iEntryId) {
  697. if ($this->_oDb->deleteEntryByIdAndOwner($iEntryId, $iProfileId, false))
  698. $this->onEventDeleted ($iEntryId);
  699. }
  700. // delete from list of fans/admins
  701. $this->_oDb->removeFanFromAllEntries ($iProfileId);
  702. $this->_oDb->removeAdminFromAllEntries ($iProfileId);
  703. }
  704. function serviceResponseAccountDelete ($oAlert) {
  705. if (!($iAccountId = (int)$oAlert->iObject))
  706. return false;
  707. // TODO: get all account's profiles and delete all profiles' data
  708. return true;
  709. }
  710. function serviceResponseProfileDelete ($oAlert) {
  711. if (!($iProfileId = (int)$oAlert->iObject))
  712. return false;
  713. $this->serviceDeleteProfileData ($iProfileId);
  714. return true;
  715. }
  716. function serviceResponseMediaDelete ($oAlert) {
  717. $iMediaId = (int)$oAlert->iObject;
  718. if (!$iMediaId)
  719. return false;
  720. switch ($oAlert->sUnit) {
  721. case 'bx_videos':
  722. $sMediaType = 'videos';
  723. break;
  724. case 'bx_sounds':
  725. $sMediaType = 'sounds';
  726. break;
  727. case 'bx_photos':
  728. $sMediaType = 'images';
  729. break;
  730. case 'bx_files':
  731. $sMediaType = 'files';
  732. break;
  733. default:
  734. return false;
  735. }
  736. return $this->_oDb->deleteMediaFile ($iMediaId, $sMediaType);
  737. }
  738. function _serviceGetMemberMenuItem ($sTitle, $sAlt, $sIcon) {
  739. if (!$this->_iProfileId)
  740. return '';
  741. $oMemberMenu = bx_instance('BxDolMemberMenu');
  742. $aLinkInfo = array(
  743. 'item_img_src' => $this->_oTemplate->getIconUrl ($sIcon),
  744. 'item_img_alt' => $sAlt,
  745. 'item_link' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'browse/my/',
  746. 'item_onclick' => null,
  747. 'item_title' => $sTitle,
  748. 'extra_info' => $this->_oDb->getCountByAuthorAndStatus($this->_iProfileId, 'approved') + $this->_oDb->getCountByAuthorAndStatus($this->_iProfileId, 'pending'),
  749. );
  750. return $oMemberMenu -> getGetExtraMenuLink($aLinkInfo);
  751. }
  752. function _serviceGetWallPost ($aEvent, $sTextWallObject, $sTextAddedNew) {
  753. if (!($aProfile = getProfileInfo($aEvent['owner_id'])))
  754. return '';
  755. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner ($aEvent['object_id'], $aEvent['owner_id'], 0)))
  756. return '';
  757. $sCss = '';
  758. if($aEvent['js_mode'])
  759. $sCss = $this->_oTemplate->addCss('wall_post.css', true);
  760. else
  761. $this->_oTemplate->addCss('wall_post.css');
  762. $aVars = array(
  763. 'cpt_user_name' => $aProfile['NickName'],
  764. 'cpt_added_new' => $sTextAddedNew,
  765. 'cpt_object' => $sTextWallObject,
  766. 'cpt_item_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  767. 'post_id' => $aEvent['id'],
  768. );
  769. return array(
  770. 'title' => $aProfile['username'] . ' ' . $sTextAddedNew . ' ' . $sTextWallObject,
  771. 'description' => $aDataEntry[$this->_oDb->_sFieldDesc],
  772. 'content' => $sCss . $this->_oTemplate->parseHtmlByName('wall_post', $aVars)
  773. );
  774. }
  775. function serviceGetWallData () {
  776. return array(
  777. 'handlers' => array(
  778. array('alert_unit' => $this->_sPrefix, 'alert_action' => 'add', 'module_uri' => $this->_aModule['uri'], 'module_class' => 'Module', 'module_method' => 'get_wall_post')
  779. ),
  780. 'alerts' => array(
  781. array('unit' => $this->_sPrefix, 'action' => 'add')
  782. )
  783. );
  784. }
  785. function _serviceGetSpyPost($sAction, $iObjectId, $iSenderId, $aExtraParams, $aLangKeys)
  786. {
  787. $aProfile = getProfileInfo($iSenderId);
  788. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner ($iObjectId, 0, true)))
  789. return array();
  790. if (empty($aLangKeys[$sAction]))
  791. return array();
  792. return array(
  793. 'lang_key' => $aLangKeys[$sAction],
  794. 'params' => array(
  795. 'profile_link' => $aProfile ? getProfileLink($iSenderId) : 'javascript:void(0)',
  796. 'profile_nick' => $aProfile ? $aProfile['NickName'] : _t('_Guest'),
  797. 'entry_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  798. 'entry_title' => $aDataEntry[$this->_oDb->_sFieldTitle],
  799. ),
  800. 'recipient_id' => $aDataEntry[$this->_oDb->_sFieldAuthorId],
  801. 'spy_type' => 'content_activity',
  802. );
  803. }
  804. function serviceGetSpyData () {
  805. return array(
  806. 'handlers' => array(
  807. array('alert_unit' => $this->_sPrefix, 'alert_action' => 'add', 'module_uri' => $this->_aModule['uri'], 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  808. array('alert_unit' => $this->_sPrefix, 'alert_action' => 'change', 'module_uri' => $this->_aModule['uri'], 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  809. array('alert_unit' => $this->_sPrefix, 'alert_action' => 'join', 'module_uri' => $this->_aModule['uri'], 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  810. array('alert_unit' => $this->_sPrefix, 'alert_action' => 'rate', 'module_uri' => $this->_aModule['uri'], 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  811. array('alert_unit' => $this->_sPrefix, 'alert_action' => 'commentPost', 'module_uri' => $this->_aModule['uri'], 'module_class' => 'Module', 'module_method' => 'get_spy_post'),
  812. ),
  813. 'alerts' => array(
  814. array('unit' => $this->_sPrefix, 'action' => 'add'),
  815. array('unit' => $this->_sPrefix, 'action' => 'change'),
  816. array('unit' => $this->_sPrefix, 'action' => 'join'),
  817. array('unit' => $this->_sPrefix, 'action' => 'rate'),
  818. array('unit' => $this->_sPrefix, 'action' => 'commentPost'),
  819. )
  820. );
  821. }
  822. function _serviceGetSubscriptionParams ($sAction, $iEntryId, $aAction2Name) {
  823. if (!($aDataEntry = $this->_oDb->getEntryByIdAndOwner ($iEntryId, 0, true)) || $aDataEntry[$this->_oDb->_sFieldStatus] != 'approved') {
  824. return array('skip' => true);
  825. }
  826. if (isset($aAction2Name[$sAction]))
  827. $sActionName = $aAction2Name[$sAction];
  828. else
  829. $sActionName = '';
  830. return array (
  831. 'skip' => false,
  832. 'template' => array (
  833. 'Subscription' => $aDataEntry[$this->_oDb->_sFieldTitle] . ($sActionName ? ' (' . $sActionName . ')' : ''),
  834. 'EntryTitle' => $aDataEntry[$this->_oDb->_sFieldTitle],
  835. 'ActionName' => $sActionName,
  836. 'ViewLink' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  837. ),
  838. );
  839. }
  840. // ================================== admin actions
  841. function _actionAdministrationSettings ($sSettingsCatName) {
  842. if (!preg_match('/^[A-Za-z0-9_-]+$/', $sSettingsCatName))
  843. return MsgBox(_t('_sys_request_page_not_found_cpt'));
  844. $iId = $this->_oDb->getSettingsCategory($sSettingsCatName);
  845. if(empty($iId))
  846. return MsgBox(_t('_sys_request_page_not_found_cpt'));
  847. bx_import('BxDolAdminSettings');
  848. $mixedResult = '';
  849. if(isset($_POST['save']) && isset($_POST['cat'])) {
  850. $oSettings = new BxDolAdminSettings($iId);
  851. $mixedResult = $oSettings->saveChanges($_POST);
  852. }
  853. $oSettings = new BxDolAdminSettings($iId);
  854. $sResult = $oSettings->getForm();
  855. if($mixedResult !== true && !empty($mixedResult))
  856. $sResult = $mixedResult . $sResult;
  857. $aVars = array (
  858. 'content' => $sResult,
  859. );
  860. return $this->_oTemplate->parseHtmlByName('default_padding', $aVars);
  861. }
  862. function _actionAdministrationManage ($isAdminEntries, $sKeyBtnDelete, $sKeyBtnActivate) {
  863. if ($_POST['action_activate'] && is_array($_POST['entry'])) {
  864. foreach ($_POST['entry'] as $iId) {
  865. if ($this->_oDb->activateEntry($iId)) {
  866. $this->onEventChanged ($iId, 'approved');
  867. }
  868. }
  869. } elseif ($_POST['action_delete'] && is_array($_POST['entry'])) {
  870. foreach ($_POST['entry'] as $iId) {
  871. $aDataEntry = $this->_oDb->getEntryById($iId);
  872. if (!$this->isAllowedDelete($aDataEntry))
  873. continue;
  874. if ($this->_oDb->deleteEntryByIdAndOwner($iId, 0, $this->isAdmin())) {
  875. $this->onEventDeleted ($iId);
  876. }
  877. }
  878. }
  879. if ($isAdminEntries) {
  880. $sContent = $this->_manageEntries ('admin', '', true, 'bx_twig_admin_form', array(
  881. 'action_delete' => $sKeyBtnDelete,
  882. ), '', true, 0, $sUrl);
  883. } else {
  884. $sContent = $this->_manageEntries ('pending', '', true, 'bx_twig_admin_form', array(
  885. 'action_activate' => $sKeyBtnActivate,
  886. 'action_delete' => $sKeyBtnDelete,
  887. ), '', true, 0, $sUrl);
  888. }
  889. return $sContent;
  890. }
  891. function actionAdministrationCreateEntry () {
  892. if (!$this->isAllowedAdd()) {
  893. $this->_oTemplate->displayAccessDenied ();
  894. return;
  895. }
  896. ob_start();
  897. $this->_addForm(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'administration/admin_entries');
  898. $aVars = array (
  899. 'content' => ob_get_clean(),
  900. );
  901. return $this->_oTemplate->parseHtmlByName('default_padding', $aVars);
  902. }
  903. // ================================== tags/cats reparse functions
  904. function reparseTags ($iEntryId) {
  905. $iEntryId = (int)$iEntryId;
  906. bx_import('BxDolTags');
  907. $o = new BxDolTags ();
  908. $o->reparseObjTags($this->_sPrefix, $iEntryId);
  909. }
  910. function reparseCategories ($iEntryId) {
  911. $iEntryId = (int)$iEntryId;
  912. bx_import('BxDolCategories');
  913. $o = new BxDolCategories ();
  914. $o->reparseObjTags($this->_sPrefix, $iEntryId);
  915. }
  916. // ================================== events
  917. function onEventCreate ($iEntryId, $sStatus, $aDataEntry = array()) {
  918. if ('approved' == $sStatus) {
  919. $this->reparseTags ($iEntryId);
  920. $this->reparseCategories ($iEntryId);
  921. }
  922. $oAlert = new BxDolAlerts($this->_sPrefix, 'add', $iEntryId, $this->_iProfileId, array('Status' => $sStatus));
  923. $oAlert->alert();
  924. }
  925. function onEventChanged ($iEntryId, $sStatus) {
  926. $this->reparseTags ($iEntryId);
  927. $this->reparseCategories ($iEntryId);
  928. $oAlert = new BxDolAlerts($this->_sPrefix, 'change', $iEntryId, $this->_iProfileId, array('Status' => $sStatus));
  929. $oAlert->alert();
  930. }
  931. function onEventDeleted ($iEntryId, $aDataEntry = array()) {
  932. // delete associated tags and categories
  933. $this->reparseTags ($iEntryId);
  934. $this->reparseCategories ($iEntryId);
  935. // delete votings
  936. bx_import('Voting', $this->_aModule);
  937. $sClass = $this->_aModule['class_prefix'] . 'Voting';
  938. $oVoting = new $sClass ($this->_sPrefix, 0, 0);
  939. $oVoting->deleteVotings ($iEntryId);
  940. // delete comments
  941. bx_import('Cmts', $this->_aModule);
  942. $sClass = $this->_aModule['class_prefix'] . 'Cmts';
  943. $oCmts = new $sClass ($this->_sPrefix, $iEntryId);
  944. $oCmts->onObjectDelete ();
  945. // delete views
  946. bx_import ('BxDolViews');
  947. $oViews = new BxDolViews($this->_sPrefix, $iEntryId, false);
  948. $oViews->onObjectDelete();
  949. // arise alert
  950. $oAlert = new BxDolAlerts($this->_sPrefix, 'delete', $iEntryId, $this->_iProfileId);
  951. $oAlert->alert();
  952. }
  953. function onEventMarkAsFeatured ($iEntryId, $aDataEntry) {
  954. // arise alert
  955. $oAlert = new BxDolAlerts($this->_sPrefix, 'mark_as_featured', $iEntryId, $this->_iProfileId, array('Featured' => $aDataEntry[$this->_oDb->_sFieldFeatured]));
  956. $oAlert->alert();
  957. }
  958. function onEventJoin ($iEntryId, $iProfileId, $aDataEntry) {
  959. // we do not need to send any notofication mail here because it will be part of standard subscription process
  960. $oAlert = new BxDolAlerts($this->_sPrefix, 'join', $iEntryId, $iProfileId);
  961. $oAlert->alert();
  962. }
  963. function _onEventJoinRequest ($iEntryId, $iProfileId, $aDataEntry, $sEmailTemplate, $iMaxFans = 1000) {
  964. $iNum = $this->_oDb->getAdmins($aGroupAdmins, $iEntryId, 0, $iMaxFans);
  965. foreach ($aGroupAdmins as $aProfile)
  966. $this->_notifyEmail ($sEmailTemplate, $aProfile['ID'], $aDataEntry);
  967. $oAlert = new BxDolAlerts($this->_sPrefix, 'join_request', $iEntryId, $iProfileId);
  968. $oAlert->alert();
  969. }
  970. function _onEventJoinReject ($iEntryId, $iProfileId, $aDataEntry, $sEmailTemplate) {
  971. $this->_notifyEmail ($sEmailTemplate, $iProfileId, $aDataEntry);
  972. $oAlert = new BxDolAlerts($this->_sPrefix, 'join_reject', $iEntryId, $iProfileId);
  973. $oAlert->alert();
  974. }
  975. function _onEventFanRemove ($iEntryId, $iProfileId, $aDataEntry, $sEmailTemplate) {
  976. $this->_notifyEmail ($sEmailTemplate, $iProfileId, $aDataEntry);
  977. $oAlert = new BxDolAlerts($this->_sPrefix, 'fan_remove', $iEntryId, $iProfileId);
  978. $oAlert->alert();
  979. }
  980. function _onEventFanBecomeAdmin ($iEntryId, $iProfileId, $aDataEntry, $sEmailTemplate) {
  981. $this->_notifyEmail ($sEmailTemplate, $iProfileId, $aDataEntry);
  982. $oAlert = new BxDolAlerts($this->_sPrefix, 'fan_become_admin', $iEntryId, $iProfileId);
  983. $oAlert->alert();
  984. }
  985. function _onEventAdminBecomeFan ($iEntryId, $iProfileId, $aDataEntry, $sEmailTemplate) {
  986. $this->_notifyEmail ($sEmailTemplate, $iProfileId, $aDataEntry);
  987. $oAlert = new BxDolAlerts($this->_sPrefix, 'admin_become_fan', $iEntryId, $iProfileId);
  988. $oAlert->alert();
  989. }
  990. function _onEventJoinConfirm ($iEntryId, $iProfileId, $aDataEntry, $sEmailTemplate) {
  991. $this->_notifyEmail ($sEmailTemplate, $iProfileId, $aDataEntry);
  992. $oAlert = new BxDolAlerts($this->_sPrefix, 'join_confirm', $iEntryId, $iProfileId);
  993. $oAlert->alert();
  994. }
  995. // ================================== other function
  996. function isAdmin () {
  997. bx_import('BxDolProfile');
  998. return $GLOBALS['logged']['admin']; // TODO: && $this->_oProfile->isActive();
  999. }
  1000. function _addForm ($sRedirectUrl) {
  1001. bx_import ('FormAdd', $this->_aModule);
  1002. $sClass = $this->_aModule['class_prefix'] . 'FormAdd';
  1003. $oForm = new $sClass ($this, $this->_iProfileId);
  1004. $oForm->initChecker();
  1005. if ($oForm->isSubmittedAndValid ()) {
  1006. $sStatus = $this->_oDb->getParam($this->_sPrefix.'_autoapproval') == 'on' || $this->isAdmin() ? 'approved' : 'pending';
  1007. $aValsAdd = array (
  1008. $this->_oDb->_sFieldCreated => time(),
  1009. $this->_oDb->_sFieldUri => $oForm->generateUri(),
  1010. $this->_oDb->_sFieldStatus => $sStatus,
  1011. );
  1012. $aValsAdd[$this->_oDb->_sFieldAuthorId] = $this->_iProfileId;
  1013. $iEntryId = $oForm->insert ($aValsAdd);
  1014. if ($iEntryId) {
  1015. $this->isAllowedAdd(true); // perform action
  1016. $aDataEntry = $this->_oDb->getEntryByIdAndOwner($iEntryId, $this->_iProfileId, $this->isAdmin());
  1017. $this->onEventCreate($iEntryId, $sStatus, $aDataEntry);
  1018. if (!$sRedirectUrl)
  1019. $sRedirectUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri];
  1020. header ('Location:' . $sRedirectUrl);
  1021. exit;
  1022. } else {
  1023. MsgBox(_t('_Error Occured'));
  1024. }
  1025. } else {
  1026. echo $oForm->getCode ();
  1027. }
  1028. }
  1029. function _manageEntries ($sMode, $sValue, $isFilter, $sFormName, $aButtons, $sAjaxPaginationBlockId = '', $isMsgBoxIfEmpty = true, $iPerPage = 0) {
  1030. bx_import ('SearchResult', $this->_aModule);
  1031. $sClass = $this->_aModule['class_prefix'] . 'SearchResult';
  1032. $o = new $sClass($sMode, $sValue);
  1033. $o->sUnitTemplate = 'unit_admin';
  1034. if ($iPerPage)
  1035. $o->aCurrent['paginate']['perPage'] = $iPerPage;
  1036. $sPagination = $sActionsPanel = '';
  1037. if ($o->isError) {
  1038. $sContent = MsgBox(_t('_Error Occured'));
  1039. } elseif (!($sContent = $o->displayResultBlock())) {
  1040. if ($isMsgBoxIfEmpty)
  1041. $sContent = MsgBox(_t('_Empty'));
  1042. else
  1043. return '';
  1044. } else {
  1045. $sPagination = $sAjaxPaginationBlockId ? $o->showPaginationAjax($sAjaxPaginationBlockId) : $o->showPagination();
  1046. $sActionsPanel = $o->showAdminActionsPanel ($sFormName, $aButtons);
  1047. }
  1048. $aVars = array (
  1049. 'form_name' => $sFormName,
  1050. 'content' => $sContent,
  1051. 'pagination' => $sPagination,
  1052. 'filter_panel' => $isFilter ? $o->showAdminFilterPanel(false !== bx_get($this->_sFilterName) ? bx_get($this->_sFilterName) : '', 'filter_input_id', 'filter_checkbox_id', $this->_sFilterName) : '',
  1053. 'actions_panel' => $sActionsPanel,
  1054. );
  1055. return $this->_oTemplate->parseHtmlByName ('manage', $aVars);
  1056. }
  1057. function _preProductTabs ($sUri, $sSubTab = '') {
  1058. bx_import('BxTemplConfig');
  1059. if (BxTemplConfig::getInstance()->bAllowUnicodeInPreg)
  1060. $sReg = '/^[\pL\pN\-_]+$/u'; // unicode characters
  1061. else
  1062. $sReg = '/^[\d\w\-_]+$/u'; // latin characters only
  1063. if (!preg_match($sReg, $sUri)) {
  1064. $this->_oTemplate->displayPageNotFound ();
  1065. return false;
  1066. }
  1067. if (!($aDataEntry = $this->_oDb->getEntryByUri($sUri))) {
  1068. $this->_oTemplate->displayPageNotFound ();
  1069. return false;
  1070. }
  1071. if ($aDataEntry[$this->_oDb->_sFieldStatus] == 'pending' && !$this->isAdmin() && !($aDataEntry[$this->_oDb->_sFieldAuthorId] == $this->_iProfileId && $aDataEntry[$this->_oDb->_sFieldAuthorId])) {
  1072. $this->_oTemplate->displayPageNotFound ();
  1073. return false;
  1074. }
  1075. /*
  1076. $GLOBALS['oTopMenu']->setCustomSubHeader($aDataEntry[$this->_oDb->_sFieldTitle]);
  1077. $GLOBALS['oTopMenu']->setCustomVar($this->_sPrefix.'_view_uri', $aDataEntry[$this->_oDb->_sFieldUri]);
  1078. $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
  1079. _t('_'.$this->_sPrefix) => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'home/',
  1080. $aDataEntry[$this->_oDb->_sFieldTitle] => $sSubTab ? BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri] : '',
  1081. $sSubTab => '',
  1082. ));
  1083. */
  1084. if ((!$this->_iProfileId || $aDataEntry[$this->_oDb->_sFieldAuthorId] != $this->_iProfileId) && !$this->isAllowedView($aDataEntry, true)) {
  1085. $this->_oTemplate->displayAccessDenied ();
  1086. return false;
  1087. }
  1088. return $aDataEntry;
  1089. }
  1090. function _processFansActions ($aDataEntry, $iMaxFans = 1000) {
  1091. header('Content-type:text/html;charset=utf-8');
  1092. if (false !== bx_get('ajax_action') && $this->isAllowedManageFans($aDataEntry) && 0 == strcasecmp($_SERVER['REQUEST_METHOD'], 'POST')) {
  1093. $iEntryId = $aDataEntry[$this->_oDb->_sFieldId];
  1094. $aIds = array ();
  1095. if (false !== bx_get('ids'))
  1096. $aIds = $this->_getCleanIdsArray (bx_get('ids'));
  1097. $isShowConfirmedFansOnly = false;
  1098. switch (bx_get('ajax_action')) {
  1099. case 'remove':
  1100. $isShowConfirmedFansOnly = true;
  1101. if ($this->_oDb->removeFans($iEntryId, $aIds)) {
  1102. foreach ($aIds as $iProfileId)
  1103. $this->onEventFanRemove ($iEntryId, $iProfileId, $aDataEntry);
  1104. }
  1105. break;
  1106. case 'add_to_admins':
  1107. $isShowConfirmedFansOnly = true;
  1108. if ($this->isAllowedManageAdmins($aDataEntry) && $this->_oDb->addGroupAdmin($iEntryId, $aIds)) {
  1109. $aProfiles = array ();
  1110. $iNum = $this->_oDb->getAdmins($aProfiles, $iEntryId, 0, $iMaxFans, $aIds);
  1111. foreach ($aProfiles as $aProfile)
  1112. $this->onEventFanBecomeAdmin ($iEntryId, $aProfile['ID'], $aDataEntry);
  1113. }
  1114. break;
  1115. case 'admins_to_fans':
  1116. $isShowConfirmedFansOnly = true;
  1117. $iNum = $this->_oDb->getAdmins($aGroupAdmins, $iEntryId, 0, $iMaxFans);
  1118. if ($this->isAllowedManageAdmins($aDataEntry) && $this->_oDb->removeGroupAdmin($iEntryId, $aIds)) {
  1119. foreach ($aGroupAdmins as $aProfile) {
  1120. if (in_array($aProfile['ID'], $aIds))
  1121. $this->onEventAdminBecomeFan ($iEntryId, $aProfile['ID'], $aDataEntry);
  1122. }
  1123. }
  1124. break;
  1125. case 'confirm':
  1126. if ($this->_oDb->confirmFans($iEntryId, $aIds)) {
  1127. echo '<script type="text/javascript" language="javascript">
  1128. document.location = "' . BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . "view/" . $aDataEntry[$this->_oDb->_sFieldUri] . '";
  1129. </script>';
  1130. $aProfiles = array ();
  1131. $iNum = $this->_oDb->getFans($aProfiles, $iEntryId, true, 0, $iMaxFans, $aIds);
  1132. foreach ($aProfiles as $aProfile) {
  1133. $this->onEventJoin ($iEntryId, $aProfile['ID'], $aDataEntry);
  1134. $this->onEventJoinConfirm ($iEntryId, $aProfile['ID'], $aDataEntry);
  1135. }
  1136. }
  1137. break;
  1138. case 'reject':
  1139. if ($this->_oDb->rejectFans($iEntryId, $aIds)) {
  1140. foreach ($aIds as $iProfileId)
  1141. $this->onEventJoinReject ($iEntryId, $iProfileId, $aDataEntry);
  1142. }
  1143. break;
  1144. case 'list':
  1145. break;
  1146. }
  1147. $aProfiles = array ();
  1148. $iNum = $this->_oDb->getFans($aProfiles, $iEntryId, $isShowConfirmedFansOnly, 0, $iMaxFans);
  1149. if (!$iNum) {
  1150. echo MsgBox(_t('_Empty'));
  1151. } else {
  1152. echo $this->_profilesEdit ($aProfiles, true, $aDataEntry);
  1153. }
  1154. exit;
  1155. }
  1156. }
  1157. function _getCleanIdsArray ($sIds, $sDivider = ',') {
  1158. $a = explode($sDivider, $sIds);
  1159. $aRet = array();
  1160. foreach ($a as $iId) {
  1161. if (!(int)$iId)
  1162. continue;
  1163. $aRet[] = (int)$iId;
  1164. }
  1165. return $aRet;
  1166. }
  1167. function _profilesEdit(&$aProfiles, $isCenterContent = true, $aDataEntry = array()) {
  1168. $sResult = "";
  1169. foreach($aProfiles as $aProfile) {
  1170. $aVars = array(
  1171. 'id' => $aProfile['ID'],
  1172. 'thumb' => get_member_thumbnail($aProfile['ID'], 'none', true),
  1173. 'bx_if:admin' => array (
  1174. 'condition' => $aDataEntry && $this->isEntryAdmin ($aDataEntry, $aProfile['ID']) ? true : false,
  1175. 'content' => array (),
  1176. ),
  1177. );
  1178. $sResult .= $this->_oTemplate->parseHtmlByName('unit_fan', $aVars);
  1179. }
  1180. return $isCenterContent ? $GLOBALS['oFunctions']->centerContent ($sResult, '.sys_fan_unit') : $sResult;
  1181. }
  1182. function _notifyEmail ($sEmailTemplateName, $iRecipient, $aDataEntry) {
  1183. if (!($aProfile = getProfileInfo ($iRecipient)))
  1184. return false;
  1185. bx_import ('BxDolEmailTemplates');
  1186. $oEmailTemplate = new BxDolEmailTemplates();
  1187. if (!$oEmailTemplate)
  1188. return false;
  1189. $aTemplate = $oEmailTemplate->getTemplate($sEmailTemplateName);
  1190. $aTemplateVars = array (
  1191. 'EntryTitle' => $aDataEntry[$this->_oDb->_sFieldTitle],
  1192. 'EntryUrl' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aDataEntry[$this->_oDb->_sFieldUri],
  1193. );
  1194. return sendMail($aProfile['Email'], $aTemplate['Subject'], $aTemplate['Body'], $aProfile['ID'], $aTemplateVars);
  1195. }
  1196. function _browseMy (&$aProfile, $sTitle) {
  1197. // check access
  1198. if (!$this->_iProfileId) {
  1199. $this->_oTemplate->displayAccessDenied();
  1200. return;
  1201. }
  1202. $bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
  1203. // process delete action
  1204. if (bx_get('action_delete') && is_array(bx_get('entry'))) {
  1205. $aEntries = bx_get('entry');
  1206. foreach ($aEntries as $iEntryId) {
  1207. $iEntryId = (int)$iEntryId;
  1208. $aDataEntry = $this->_oDb->getEntryById($iEntryId);
  1209. if (!$this->isAllowedDelete($aDataEntry))
  1210. continue;
  1211. if ($this->_oDb->deleteEntryByIdAndOwner($iEntryId, $this->_iProfileId, 0)) {
  1212. $this->onEventDeleted ($iEntryId);
  1213. }
  1214. }
  1215. }
  1216. bx_import ('PageMy', $this->_aModule);
  1217. $sClass = $this->_aModule['class_prefix'] . 'PageMy';
  1218. $oPage = new $sClass ($this, $aProfile);
  1219. // manage my data entries
  1220. if ($bAjaxMode && ($this->_sPrefix . '_my_active') == bx_get('block')) {
  1221. header('Content-type:text/html;charset=utf-8');
  1222. echo $oPage->getBlockCode_My();
  1223. exit;
  1224. }
  1225. // manage my pending data entries
  1226. if ($bAjaxMode && ($this->_sPrefix . '_my_pending') == bx_get('block')) {
  1227. header('Content-type:text/html;charset=utf-8');
  1228. echo $oPage->getBlockCode_Pending();
  1229. exit;
  1230. }
  1231. $this->_oTemplate->pageStart();
  1232. // display whole page
  1233. if (!$bAjaxMode)
  1234. echo $oPage->getCode();
  1235. $this->_oTemplate->addJs ('main.js');
  1236. $this->_oTemplate->addCss ('main.css');
  1237. $this->_oTemplate->addCss ('form.css');
  1238. $this->_oTemplate->addCss ('admin.css');
  1239. $this->_oTemplate->addCss ('forms_extra.css');
  1240. $this->_oTemplate->pageCode($sTitle, false, false);
  1241. }
  1242. function isMembershipEnabledForImages () {
  1243. return $this->_isMembershipEnabledFor ('BX_PHOTOS_ADD');
  1244. }
  1245. function isMembershipEnabledForVideos () {
  1246. return $this->_isMembershipEnabledFor ('BX_VIDEOS_ADD');
  1247. }
  1248. function isMembershipEnabledForSounds () {
  1249. return $this->_isMembershipEnabledFor ('BX_SOUNDS_ADD');
  1250. }
  1251. function isMembershipEnabledForFiles () {
  1252. return $this->_isMembershipEnabledFor ('BX_FILES_ADD');
  1253. }
  1254. function _isMembershipEnabledFor ($sMembershipActionConstant) {
  1255. defineMembershipActions (array('photos add', 'sounds add', 'videos add', 'files add'));
  1256. if (!defined($sMembershipActionConstant))
  1257. return false;
  1258. $aCheck = checkAction(getLoggedId(), constant($sMembershipActionConstant));
  1259. return $aCheck[CHECK_ACTION_RESULT] == CHECK_ACTION_RESULT_ALLOWED;
  1260. }
  1261. function _formatSnippetText ($aEntryData, $iMaxLen = 300) {
  1262. return strmaxtextlen($aEntryData[$this->_oDb->_sFieldDescription], $iMaxLen);
  1263. }
  1264. }
  1265. ?>