BxDolTextModule.php 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933
  1. <?php
  2. // TODO: decide later what to do with text* classes and module, it looks like they will stay and text 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('BxDolViews');
  23. bx_import('BxDolAlerts');
  24. bx_import('BxDolModule');
  25. bx_import('BxDolPaginate');
  26. //bx_import('BxDolCategories');
  27. bx_import('BxDolRssFactory');
  28. //bx_import('BxDolSubscription');
  29. //bx_import('BxTemplTagsModule');
  30. //bx_import('BxTemplCategoriesModule');
  31. require_once(BX_DIRECTORY_PATH_PLUGINS . 'Services_JSON.php');
  32. class BxDolTextModule extends BxDolModule {
  33. var $_oTextData;
  34. var $_oPrivacy;
  35. function BxDolTextModule($aModule) {
  36. parent::BxDolModule($aModule);
  37. $this->_oConfig->init($this->_oDb);
  38. $this->_oTemplate->init($this);
  39. $sClassPrefix = $this->_oConfig->getClassPrefix();
  40. $sClassName = $sClassPrefix . 'Privacy';
  41. $this->_oPrivacy = class_exists($sClassName) ? new $sClassName($this) : null;
  42. $sClassName = $sClassPrefix . 'Data';
  43. $this->_oTextData = class_exists($sClassName) ? new $sClassName($this) : null;
  44. }
  45. function getBlockView($sUri)
  46. {
  47. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'uri', 'uri' => $sUri));
  48. if(empty($aEntry) || !is_array($aEntry))
  49. $this->_oTemplate->displayPageNotFound();
  50. $sModuleUri = $this->_oConfig->getUri();
  51. $oView = new BxDolViews($this->_oConfig->getViewsSystemName(), $aEntry['id']);
  52. $oView->makeView();
  53. $this->_oTemplate->setPageTitle($aEntry['caption']);
  54. $GLOBALS['oTopMenu']->setCustomSubHeader($aEntry['caption']);
  55. $GLOBALS['oTopMenu']->setCustomBreadcrumbs(array(
  56. _t('_' . $sModuleUri . '_top_menu_item') => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'index/',
  57. $aEntry['caption'] => '')
  58. );
  59. return $this->_oTemplate->displayList(array(
  60. 'sample_type' => 'view',
  61. 'viewer_type' => $this->_oTextData->getViewerType(),
  62. 'uri' => $aEntry['uri']
  63. ));
  64. }
  65. function getBlockComment($sUri)
  66. {
  67. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'uri', 'uri' => $sUri));
  68. if(!$this->_oConfig->isCommentsEnabled() || !$this->_isCommentsAllowed($aEntry))
  69. return '';
  70. $sModuleUri = $this->_oConfig->getUri();
  71. if($aEntry['status'] != BX_TD_STATUS_ACTIVE)
  72. return MsgBox(_t('_' . $sModuleUri . '_msg_no_results'));
  73. $this->_oTemplate->addCss(array('cmts.css'));
  74. $oComments = $this->_createObjectCmts($aEntry['id']);
  75. return $oComments->getCommentsFirst('comment');
  76. }
  77. function getBlockVote($sUri)
  78. {
  79. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'uri', 'uri' => $sUri));
  80. if(!$this->_oConfig->isVotesEnabled() || !$this->_isVotesAllowed($aEntry))
  81. return '';
  82. $sModuleUri = $this->_oConfig->getUri();
  83. if($aEntry['status'] != BX_TD_STATUS_ACTIVE)
  84. return MsgBox(_t('_' . $sModuleUri . '_msg_no_results'));
  85. $oVotes = $this->_createObjectVoting($aEntry['id']);
  86. return $oVotes->getBigVoting();
  87. }
  88. function getBlockAction($sUri)
  89. {
  90. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'uri', 'uri' => $sUri));
  91. $sModuleUri = $this->_oConfig->getUri();
  92. $sModuleBaseUri = $this->_oConfig->getBaseUri();
  93. if($aEntry['status'] != BX_TD_STATUS_ACTIVE)
  94. return MsgBox(_t('_' . $sModuleUri . '_msg_no_results'));
  95. $sModuleUri = $this->_oConfig->getUri();
  96. $oSubscription = new BxDolSubscription();
  97. $aButton = $oSubscription->getButton($this->getUserId(), $this->_oConfig->getSubscriptionsSystemName(), '', $aEntry['id']);
  98. $aReplacement['sbs_' . $sModuleUri . '_title'] = $aButton['title'];
  99. $aReplacement['sbs_' . $sModuleUri . '_script'] = $aButton['script'];
  100. $aReplacement['del_' . $sModuleUri . '_title'] = '';
  101. if($this->_isDeleteAllowed()) {
  102. $this->_oTemplate->addJsTranslation(array('_' . $sModuleUri . '_msg_success_delete', '_' . $sModuleUri . '_msg_failed_delete'));
  103. $aReplacement['del_' . $sModuleUri . '_title'] = _t('_' . $sModuleUri . '_actions_delete');
  104. $aReplacement['del_' . $sModuleUri . '_script'] = $this->_oConfig->getJsObject() . '.deleteEntry(' . $aEntry['id'] . ')';
  105. }
  106. $aReplacement['share_' . $sModuleUri . '_title'] = '';
  107. if($this->_isShareAllowed($aEntry)) {
  108. $aReplacement['share_' . $sModuleUri . '_title'] = _t('_Share');
  109. $aReplacement['share_' . $sModuleUri . '_script'] = "showPopupAnyHtml('" . $sModuleBaseUri . "share_popup/" . $aEntry['id'] . "')";
  110. }
  111. return $oSubscription->getData() . $GLOBALS['oFunctions']->genObjectsActions($aReplacement, $this->_oConfig->getActionsViewSystemName());
  112. }
  113. function getBlockSocialSharing($sUri)
  114. {
  115. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'uri', 'uri' => $sUri));
  116. if(!$aEntry || $aEntry['status'] != BX_TD_STATUS_ACTIVE)
  117. return '';
  118. $sUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aEntry['uri'];
  119. $sTitle = $aEntry['caption'];
  120. bx_import('BxTemplSocialSharing');
  121. $s = BxTemplSocialSharing::getInstance()->getCode($sUrl, $sTitle);
  122. return array($s, array(), array(), false);
  123. }
  124. function getCalendar($iYear = 0, $iMonth = 0)
  125. {
  126. $sClassName = $this->_oConfig->getClassPrefix() . 'Calendar';
  127. return new $sClassName($iYear, $iMonth, $this->_oDb, $this->_oConfig);
  128. }
  129. function getSearchResult() {
  130. $sClassName = $this->_oConfig->getClassPrefix() . 'SearchResult';
  131. return new $sClassName($this);
  132. }
  133. function getSearchContent($aRestrictions, $sUri, $iPage = 1, $iPerPage = 0) {
  134. $iPerPage = !empty($iPerPage) ? $iPerPage : $this->_oConfig->getPerPage();
  135. $sClassName = $this->_oConfig->getClassPrefix() . 'SearchResult';
  136. $oSearchResult = new $sClassName($this);
  137. foreach($aRestrictions as $sKey => $mixedValue)
  138. if(is_array($mixedValue))
  139. $oSearchResult->aCurrent['restriction'][$sKey] = $mixedValue;
  140. else if(is_string($mixedValue))
  141. $oSearchResult->aCurrent['restriction'][$sKey]['value'] = $mixedValue;
  142. $oSearchResult->aCurrent['paginate']['forcePage'] = $iPage;
  143. $oSearchResult->aCurrent['paginate']['perPage'] = $iPerPage;
  144. $sCode = $oSearchResult->displayResultBlock();
  145. if(!empty($sCode)) {
  146. $oPaginate = new BxDolPaginate(array(
  147. 'page_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . $sUri . '{page}/{per_page}',
  148. 'count' => $oSearchResult->aCurrent['paginate']['totalNum'],
  149. 'per_page' => $iPerPage,
  150. 'page' => $iPage,
  151. 'per_page_changer' => true,
  152. 'page_reloader' => false,
  153. 'on_change_page' => '',
  154. 'on_change_per_page' => '',
  155. ));
  156. $sCode .= $oPaginate->getPaginate();
  157. }
  158. return $sCode;
  159. }
  160. function getCategoryContent($sCategory, $iPage = 1, $iPerPage = 0) {
  161. $sCategory = uri2title(process_db_input($sCategory, BX_TAGS_STRIP));
  162. $iPage = (int)$iPage;
  163. $iPerPage = (int)$iPerPage;
  164. $sCategoryDisplay = $GLOBALS['MySQL']->unescape($sCategory);
  165. return array(
  166. $sCategoryDisplay,
  167. $this->getSearchContent(array('category' => $sCategory), 'category/' . title2uri($sCategoryDisplay) . '/', $iPage, $iPerPage)
  168. );
  169. }
  170. function getTagContent($sTag = '', $iPage = 1, $iPerPage = 0) {
  171. $sTag = uri2title(process_db_input($sTag, BX_TAGS_STRIP));
  172. $iPage = (int)$iPage;
  173. $iPerPage = (int)$iPerPage;
  174. $sTagDisplay = $GLOBALS['MySQL']->unescape($sTag);
  175. return array(
  176. $sTagDisplay,
  177. $this->getSearchContent(array('tag' => $sTag), 'tag/' . title2uri($sTagDisplay) . '/', $iPage, $iPerPage)
  178. );
  179. }
  180. function getCalendarContent($iYear, $iMonth, $iDay, $iPage, $iPerPage) {
  181. $iYear = (int)$iYear;
  182. $iMonth = (int)$iMonth;
  183. $iDay = (int)$iDay;
  184. $iPage = (int)$iPage;
  185. $iPerPage = (int)$iPerPage;
  186. return $this->getSearchContent(
  187. array(
  188. 'calendar-min' => array('value' => "UNIX_TIMESTAMP('" . $iYear . "-" . $iMonth . "-" . $iDay . " 00:00:00')", 'field' => 'when', 'operator' => '>=', 'no_quote_value' => true),
  189. 'calendar-max' => array('value' => "UNIX_TIMESTAMP('" . $iYear . "-" . $iMonth . "-" . $iDay . " 23:59:59')", 'field' => 'when', 'operator' => '<=', 'no_quote_value' => true),
  190. ),
  191. 'calendar/' . $iYear . '/' . $iMonth . '/' . $iDay . '/',
  192. $iPage,
  193. $iPerPage
  194. );
  195. }
  196. /**
  197. * Admin Settings Methods
  198. */
  199. function getSettingsForm($mixedResult) {
  200. $sUri = $this->_oConfig->getUri();
  201. $iId = (int)$this->_oDb->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name`='" . ucwords(str_replace('_', ' ', $sUri)) . "'");
  202. if(empty($iId))
  203. return MsgBox('_' . $sUri . '_msg_no_results');
  204. $oSettings = new BxDolAdminSettings($iId, BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'admin');
  205. $sResult = $oSettings->getForm();
  206. if($mixedResult !== true && !empty($mixedResult))
  207. $sResult = $mixedResult . $sResult;
  208. return $sResult;
  209. }
  210. function setSettings($aData) {
  211. $sUri = $this->_oConfig->getUri();
  212. $iId = (int)$this->_oDb->getOne("SELECT `ID` FROM `sys_options_cats` WHERE `name`='" . ucwords(str_replace('_', ' ', $sUri)) . "'");
  213. if(empty($iId))
  214. return MsgBox(_t('_' . $sUri . '_msg_no_results'));
  215. $oSettings = new BxDolAdminSettings($iId);
  216. return $oSettings->saveChanges($_POST);
  217. }
  218. /**
  219. * Service methods
  220. */
  221. function servicePostBlock() {
  222. $aVariables = array(
  223. 'include_css' => $this->_oTemplate->addCss(array('post.css'), true),
  224. 'post_form' => $this->_oTextData->getPostForm()
  225. );
  226. return $this->_oTemplate->parseHtmlByName('post.html', $aVariables);
  227. }
  228. function serviceEditBlock($mixed) {
  229. if(is_string($mixed))
  230. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'uri', 'uri' => $mixed));
  231. else if(is_int($mixed))
  232. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'id', 'id' => $mixed));
  233. $aVariables = array(
  234. 'include_css' => $this->_oTemplate->addCss(array('post.css'), true),
  235. 'post_form' => $this->_oTextData->getEditForm($aEntry)
  236. );
  237. return $this->_oTemplate->parseHtmlByName('post.html', $aVariables);
  238. }
  239. function serviceAdminBlock($iStart = 0, $iPerPage = 0, $sFilterValue = '') {
  240. if(empty($iPerPage))
  241. $iPerPage = $this->_oConfig->getPerPage();
  242. return $this->_oTemplate->displayAdminBlock(array(
  243. 'sample_type' => 'admin',
  244. 'viewer_type' => $this->_oTextData->getViewerType(),
  245. 'start' => $iStart,
  246. 'count' => $iPerPage,
  247. 'admin_panel' => true,
  248. 'filter_value' => $sFilterValue,
  249. 'search_result_object' => $this->getSearchResult()
  250. ));
  251. }
  252. function serviceArchiveBlockIndex($iStart = 0, $iPerPage = 0, $bShowEmpty = true) {
  253. if(empty($iPerPage))
  254. $iPerPage = $this->_oConfig->getIndexNumber();
  255. return $this->serviceArchiveBlock($iStart, $iPerPage, $bShowEmpty);
  256. }
  257. function serviceArchiveBlockMember($iStart = 0, $iPerPage = 0, $bShowEmpty = true) {
  258. if(empty($iPerPage))
  259. $iPerPage = $this->_oConfig->getMemberNumber();
  260. return $this->serviceArchiveBlock($iStart, $iPerPage, $bShowEmpty);
  261. }
  262. function serviceArchiveBlock($iStart = 0, $iPerPage = 0, $bShowEmpty = true) {
  263. if(empty($iPerPage))
  264. $iPerPage = $this->_oConfig->getPerPage();
  265. return $this->_oTemplate->displayBlock(array(
  266. 'sample_type' => 'archive',
  267. 'viewer_type' => $this->_oTextData->getViewerType(),
  268. 'start' => $iStart,
  269. 'count' => $iPerPage,
  270. 'show_empty' => $bShowEmpty
  271. ));
  272. }
  273. function serviceFeaturedBlockIndex($iStart = 0, $iPerPage = 0, $bShowEmpty = true) {
  274. if(empty($iPerPage))
  275. $iPerPage = $this->_oConfig->getIndexNumber();
  276. return $this->serviceFeaturedBlock($iStart, $iPerPage, $bShowEmpty);
  277. }
  278. function serviceFeaturedBlockMember($iStart = 0, $iPerPage = 0, $bShowEmpty = true) {
  279. if(empty($iPerPage))
  280. $iPerPage = $this->_oConfig->getMemberNumber();
  281. return $this->serviceFeaturedBlock($iStart, $iPerPage, $bShowEmpty);
  282. }
  283. function serviceFeaturedBlock($iStart = 0, $iPerPage = 0, $bShowEmpty = true) {
  284. if(empty($iPerPage))
  285. $iPerPage = $this->_oConfig->getPerPage();
  286. return $this->_oTemplate->displayBlock(array(
  287. 'sample_type' => 'featured',
  288. 'viewer_type' => $this->_oTextData->getViewerType(),
  289. 'start' => $iStart,
  290. 'count' => $iPerPage,
  291. 'show_empty' => $bShowEmpty
  292. ));
  293. }
  294. function serviceTopRatedBlock($iStart = 0, $iPerPage = 0) {
  295. if(empty($iPerPage))
  296. $iPerPage = $this->_oConfig->getPerPage();
  297. return $this->_oTemplate->displayBlock(array(
  298. 'sample_type' => 'top_rated',
  299. 'viewer_type' => $this->_oTextData->getViewerType(),
  300. 'start' => $iStart,
  301. 'count' => $iPerPage
  302. ));
  303. }
  304. function serviceCategoriesBlock($iBlockId) {
  305. $sUri = $this->_oConfig->getUri();
  306. $oCategories = new BxTemplCategoriesModule(array('type' => $this->_oConfig->getCategoriesSystemName()), _t('_categ_users'), BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'category');
  307. return $oCategories->getBlockCode_Common($iBlockId, true);
  308. }
  309. function serviceTagsBlock($iBlockId) {
  310. $sUri = $this->_oConfig->getUri();
  311. $oTags = new BxTemplTagsModule(array('type' => $this->_oConfig->getTagsSystemName(), 'orderby' => 'popular'), _t('_' . $sUri . '_bcaption_all_tags'), BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'tags');
  312. $aResult = $oTags->getBlockCode_All($iBlockId);
  313. return $aResult[0];
  314. }
  315. function serviceGetCalendarBlock($iBlockID, $aParams = array()) {
  316. $isMiniMode = isset($aParams['mini_mode']) && $aParams['mini_mode'] === true;
  317. $sDynamicUrl = isset($aParams['dynamic_url']) ? $aParams['dynamic_url'] : BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'index/';
  318. $aDateParams = array();
  319. $sDate = bx_get('date');
  320. if($sDate) {
  321. $aDateParams = explode('/', $sDate);
  322. }
  323. $oCalendar = $this->_createObjectCalendar((int)$aDateParams[0], (int)$aDateParams[1]);
  324. $oCalendar->setBlockId($iBlockID);
  325. $oCalendar->setDynamicUrl($sDynamicUrl);
  326. return $oCalendar->display($isMiniMode);
  327. }
  328. function servicePopularBlock($iStart = 0, $iPerPage = 0) {
  329. if(empty($iPerPage))
  330. $iPerPage = $this->_oConfig->getPerPage();
  331. return $this->_oTemplate->displayBlock(array(
  332. 'sample_type' => 'popular',
  333. 'viewer_type' => $this->_oTextData->getViewerType(),
  334. 'start' => $iStart,
  335. 'count' => $iPerPage
  336. ));
  337. }
  338. function serviceGetSubscriptionParams($sUnit, $sAction, $iObjectId) {
  339. $sUnit = str_replace('bx_', '', $sUnit);
  340. if(empty($sAction))
  341. $sAction = 'main';
  342. $aItem = $this->_oDb->getEntries(array('sample_type' => 'id', 'id' => $iObjectId));
  343. return array(
  344. 'template' => array(
  345. 'Subscription' => _t('_' . $sUnit . '_sbs_' . $sAction, $aItem['caption']),
  346. 'ViewLink' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aItem['uri']
  347. )
  348. );
  349. }
  350. /**
  351. * Action methods
  352. */
  353. function actionRss($iLength = 0) {
  354. $iLength = $iLength != 0 ? $iLength : (int)$this->_oConfig->getRssLength();
  355. $aEntries = $this->_oDb->getEntries(array(
  356. 'sample_type' => 'archive',
  357. 'viewer_type' => $this->_oTextData->getViewerType(),
  358. 'start' => 0,
  359. 'count' => $iLength
  360. ));
  361. $aRssData = array();
  362. $sRssViewUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/';
  363. foreach($aEntries as $aEntry) {
  364. if(empty($aEntry['caption'])) continue;
  365. $aRssData[$aEntry['id']] = array(
  366. 'UnitID' => $aEntry['id'],
  367. 'OwnerID' => $aEntry['id'],
  368. 'UnitTitle' => $aEntry['caption'],
  369. 'UnitLink' => $sRssViewUrl . $aEntry['uri'],
  370. 'UnitDesc' => $aEntry['content'],
  371. 'UnitDateTimeUTS' => $aEntry['when_uts'],
  372. 'UnitIcon' => ''
  373. );
  374. }
  375. $oRss = new BxDolRssFactory();
  376. return $oRss->GenRssByData($aRssData, _t('_news_rss_caption'), $this->_oConfig->getBaseUri() . 'act_rss/');
  377. }
  378. function actiongetEntries($sSampleType = 'all', $iStart = 0, $iPerPage = 0) {
  379. check_logged();
  380. if(empty($iPerPage))
  381. $iPerPage = $this->_oConfig->getPerPage();
  382. return $this->_oTemplate->displayList(array(
  383. 'sample_type' => $sSampleType,
  384. 'sample_params' => isset($_POST['params']) ? unserialize(urldecode($_POST['params'])) : '',
  385. 'viewer_type' => $this->_oTextData->getViewerType(),
  386. 'start' => $iStart,
  387. 'count' => $iPerPage,
  388. 'filter_value' => isset($_POST['filter_value']) ? process_db_input($_POST['filter_value'], BX_TAGS_STRIP) : ''
  389. ));
  390. }
  391. function actionMarkFeatured() {
  392. $iId = (int)$_POST['id'];
  393. return !empty($iId) ? $this->_actFeatured($iId) : false;
  394. }
  395. function actionPublish() {
  396. $iId = (int)$_POST['id'];
  397. return !empty($iId) ? $this->_actPublish($iId) : false;
  398. }
  399. function actionDelete() {
  400. $iId = (int)$_POST['id'];
  401. return !empty($iId) ? $this->_actDelete($iId) : false;
  402. }
  403. function actionSharePopup($iEntry) {
  404. header('Content-type:text/html;charset=utf-8');
  405. $sUri = $this->_oConfig->getUri();
  406. $aEntry = $this->_oDb->getEntries(array('sample_type' => 'id', 'id' => (int)$iEntry));
  407. if(!$aEntry) {
  408. echo MsgBox(_t('_' . $sUri . '_msg_no_results'));
  409. exit;
  410. }
  411. $sEntryUrl = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'view/' . $aEntry['EntryUri'];
  412. require_once (BX_DIRECTORY_PATH_INC . "shared_sites.inc.php");
  413. echo getSitesHtml($sEntryUrl);
  414. exit;
  415. }
  416. function actionArchive($iStart = 0, $iPerPage = 0) {
  417. $sUri = $this->_oConfig->getUri();
  418. $aParams = array(
  419. 'title' => array(
  420. 'page' => _t('_' . $sUri . '_pcaption_archive'),
  421. 'block' => _t('_' . $sUri . '_bcaption_archive')
  422. ),
  423. 'content' => array(
  424. 'page_main_code' => $this->serviceArchiveBlock((int)$iStart, (int)$iPerPage)
  425. )
  426. );
  427. $this->_oTemplate->getPageCode($aParams);
  428. }
  429. function actionPopular() {
  430. $sUri = $this->_oConfig->getUri();
  431. $aParams = array(
  432. 'title' => array(
  433. 'page' => _t('_' . $sUri . '_pcaption_popular'),
  434. 'block' => _t('_' . $sUri . '_bcaption_popular')
  435. ),
  436. 'content' => array(
  437. 'page_main_code' => $this->servicePopularBlock()
  438. )
  439. );
  440. $this->_oTemplate->getPageCode($aParams);
  441. }
  442. function actionTop() {
  443. $sUri = $this->_oConfig->getUri();
  444. $aParams = array(
  445. 'title' => array(
  446. 'page' => _t('_' . $sUri . '_pcaption_top_rated'),
  447. 'block' => _t('_' . $sUri . '_bcaption_top_rated')
  448. ),
  449. 'content' => array(
  450. 'page_main_code' => $this->serviceTopRatedBlock()
  451. )
  452. );
  453. $this->_oTemplate->getPageCode($aParams);
  454. }
  455. function actionCalendar($iYear = 0, $iMonth = 0, $iDay = 0, $iStart = 1, $iPerPage = 0) {
  456. $sUri = $this->_oConfig->getUri();
  457. $iArgs = func_num_args();
  458. if($iArgs == 1 && is_string($iYear))
  459. $iArgs = 0;
  460. $sContent = '';
  461. switch($iArgs) {
  462. case 0:
  463. case 2:
  464. $oCalendar = $this->getCalendar((int)$iYear, (int)$iMonth);
  465. $sContent = $oCalendar->display();
  466. break;
  467. case 3:
  468. case 5:
  469. $sContent = $this->getCalendarContent((int)$iYear, (int)$iMonth, (int)$iDay, (int)$iStart, (int)$iPerPage);
  470. $sContent = strlen($sContent) > 0 ? $sContent : _t('_' . $sUri . '_msg_no_results');
  471. break;
  472. }
  473. $sBlockTitle = !$iDay
  474. ? _t('_' . $sUri . '_bcaption_calendar')
  475. : _t('_' . $sUri . '_bcaption_calendar_browse') . ': ' . getLocaleDate(
  476. strtotime("{$iYear}-{$iMonth}-{$iDay}"), BX_DOL_LOCALE_DATE_SHORT);
  477. $sPageTitle = !$iDay
  478. ? _t('_' . $sUri . '_pcaption_calendar')
  479. : $sBlockTitle;
  480. $aParams = array(
  481. 'title' => array(
  482. 'page' => $sPageTitle,
  483. 'block' => $sBlockTitle,
  484. ),
  485. 'content' => array(
  486. 'page_main_code' => $sContent
  487. )
  488. );
  489. $this->_oTemplate->getPageCode($aParams);
  490. }
  491. function actionCategories() {
  492. $sUri = $this->_oConfig->getUri();
  493. $oCategories = new BxTemplCategoriesModule(array('type' => $this->_oConfig->getCategoriesSystemName()), _t('_categ_users'), BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'categories');
  494. $aParams = array(
  495. 'index' => 1,
  496. 'css' => array('view.css'),
  497. 'title' => array(
  498. 'page' => _t('_' . $sUri . '_pcaption_categories')
  499. ),
  500. 'content' => array(
  501. 'page_main_code' => $oCategories->getCode()
  502. )
  503. );
  504. $this->_oTemplate->getPageCode($aParams);
  505. }
  506. function actionCategory($sCategory = '', $iPage = 1, $iPerPage = 0) {
  507. $sUri = $this->_oConfig->getUri();
  508. $sBaseUri = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri();
  509. $sContent = MsgBox(_t('_' . $sUri . '_msg_no_results'));
  510. if(!empty($sCategory))
  511. list($sCategoryDisplay, $sContent) = $this->getCategoryContent($sCategory, $iPage, $iPerPage);
  512. $aParams = array(
  513. 'css' => array('view.css'),
  514. 'title' => array(
  515. 'page' => _t('_' . $sUri . '_pcaption_category', $sCategoryDisplay),
  516. 'block' => _t('_' . $sUri . '_bcaption_category', $sCategoryDisplay)
  517. ),
  518. 'breadcrumb' => array(
  519. _t('_' . $sUri . '_top_menu_item') => $sBaseUri . 'home/',
  520. _t('_' . $sUri . '_categories_top_menu_sitem') => $sBaseUri . 'categories/',
  521. $sCategoryDisplay => ''
  522. ),
  523. 'content' => array(
  524. 'page_main_code' => $sContent
  525. )
  526. );
  527. $this->_oTemplate->getPageCode($aParams);
  528. }
  529. function actionTags() {
  530. $sUri = $this->_oConfig->getUri();
  531. $oTags = new BxTemplTagsModule(array('type' => $this->_oConfig->getTagsSystemName(), 'orderby' => 'popular'), _t('_' . $sUri . '_bcaption_all_tags'), BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'tags');
  532. $aParams = array(
  533. 'index' => 1,
  534. 'css' => array('view.css'),
  535. 'title' => array(
  536. 'page' => _t('_' . $sUri . '_pcaption_tags')
  537. ),
  538. 'content' => array(
  539. 'page_main_code' => $oTags->getCode()
  540. )
  541. );
  542. $this->_oTemplate->getPageCode($aParams);
  543. }
  544. function actionTag($sTag = '', $iPage = 1, $iPerPage = 0) {
  545. $sUri = $this->_oConfig->getUri();
  546. $sBaseUri = BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri();
  547. $sContent = MsgBox(_t('_' . $sUri . '_msg_no_results'));
  548. if(!empty($sTag))
  549. list($sTagDisplay, $sContent) = $this->getTagContent($sTag, $iPage, $iPerPage);
  550. $aParams = array(
  551. 'css' => array('view.css'),
  552. 'title' => array(
  553. 'page' => _t('_' . $sUri . '_pcaption_tag', $sTagDisplay),
  554. 'block' => _t('_' . $sUri . '_bcaption_tag', $sTagDisplay)
  555. ),
  556. 'breadcrumb' => array(
  557. _t('_' . $sUri . '_top_menu_item') => $sBaseUri . 'home/',
  558. _t('_' . $sUri . '_tags_top_menu_sitem') => $sBaseUri . 'tags/',
  559. $sTagDisplay => ''
  560. ),
  561. 'content' => array(
  562. 'page_main_code' => $sContent
  563. )
  564. );
  565. $this->_oTemplate->getPageCode($aParams);
  566. }
  567. function actionFeatured() {
  568. $sUri = $this->_oConfig->getUri();
  569. $aParams = array(
  570. 'title' => array(
  571. 'page' => _t('_' . $sUri . '_pcaption_featured'),
  572. 'block' => _t('_' . $sUri . '_bcaption_featured')
  573. ),
  574. 'content' => array(
  575. 'page_main_code' => $this->serviceFeaturedBlock()
  576. )
  577. );
  578. $this->_oTemplate->getPageCode($aParams);
  579. }
  580. function actionHome() {
  581. $this->actionIndex();
  582. }
  583. function actionIndex() {
  584. $sUri = $this->_oConfig->getUri();
  585. $oPage = bx_instance($this->_oConfig->getClassPrefix() . 'PageMain', array($this), $this->_aModule);
  586. $aParams = array(
  587. 'index' => 1,
  588. 'css' => array('view.css', 'cmts.css'),
  589. 'title' => array(
  590. 'page' => _t('_' . $sUri . '_pcaption_home')
  591. ),
  592. 'content' => array(
  593. 'page_main_code' => $oPage->getCode()
  594. )
  595. );
  596. $this->_oTemplate->getPageCode($aParams);
  597. }
  598. function actionView($sName) {
  599. $sUri = $this->_oConfig->getUri();
  600. $oPage = bx_instance($this->_oConfig->getClassPrefix() . 'PageView', array($sName, $this), $this->_aModule);
  601. $aParams = array(
  602. 'index' => 1,
  603. 'js' => array('main.js'),
  604. 'css' => array('view.css', 'cmts.css'),
  605. 'content' => array(
  606. 'page_main_code' => $this->_oTemplate->getViewJs(true) . $oPage->getCode()
  607. )
  608. );
  609. $this->_oTemplate->getPageCode($aParams);
  610. }
  611. function actionAdmin($sName = '') {
  612. $GLOBALS['iAdminPage'] = 1;
  613. require_once(BX_DIRECTORY_PATH_INC . 'admin_design.inc.php');
  614. $sUri = $this->_oConfig->getUri();
  615. check_logged();
  616. if(!@isAdmin()) {
  617. send_headers_page_changed();
  618. login_form("", 1);
  619. exit;
  620. }
  621. //--- Process actions ---//
  622. $mixedResultSettings = '';
  623. if(isset($_POST['save']) && isset($_POST['cat'])) {
  624. $mixedResultSettings = $this->setSettings($_POST);
  625. }
  626. if(isset($_POST[$sUri . '-publish']))
  627. $this->_actPublish($_POST[$sUri . '-ids'], true);
  628. else if(isset($_POST[$sUri . '-unpublish']))
  629. $this->_actPublish($_POST[$sUri . '-ids'], false);
  630. else if(isset($_POST[$sUri . '-featured']))
  631. $this->_actFeatured($_POST[$sUri . '-ids'], true);
  632. else if(isset($_POST[$sUri . '-unfeatured']))
  633. $this->_actFeatured($_POST[$sUri . '-ids'], false);
  634. else if(isset($_POST[$sUri . '-delete']))
  635. $this->_actDelete($_POST[$sUri . '-ids']);
  636. //--- Process actions ---//
  637. //--- Get New/Edit form ---//
  638. $sPostForm = '';
  639. if(!empty($sName))
  640. $sPostForm = $this->serviceEditBlock(process_db_input($sName, BX_TAGS_STRIP));
  641. else if(isset($_POST['id']))
  642. $sPostForm = $this->serviceEditBlock((int)$_POST['id']);
  643. else
  644. $sPostForm = $this->servicePostBlock();
  645. //--- Get New/Edit form ---//
  646. $sFilterValue = '';
  647. if(isset($_GET[$sUri . '-filter']))
  648. $sFilterValue = process_db_input($_GET[$sUri . '-filter'], BX_TAGS_STRIP);
  649. $sContent = DesignBoxAdmin(_t('_' . $sUri . '_bcaption_settings'), $GLOBALS['oAdmTemplate']->parseHtmlByName('design_box_content.html', array('content' => $this->getSettingsForm($mixedResultSettings))));
  650. $sContent .= DesignBoxAdmin(_t('_' . $sUri . '_bcaption_post'), $sPostForm);
  651. $sContent .= DesignBoxAdmin(_t('_' . $sUri . '_bcaption_all'), $this->serviceAdminBlock(0, 0, $sFilterValue));
  652. $aParams = array(
  653. 'title' => array(
  654. 'page' => _t('_' . $sUri . '_pcaption_admin')
  655. ),
  656. 'content' => array(
  657. 'page_main_code' => $sContent
  658. )
  659. );
  660. $this->_oTemplate->getPageCodeAdmin($aParams);
  661. }
  662. /**
  663. * View list of latest entries for mobile app
  664. */
  665. function actionMobileLatestEntries($iPage = 1) {
  666. $sUri = $this->_oConfig->getUri();
  667. $iPerPage = 10;
  668. $iPage = (int)$iPage;
  669. if ($iPage < 1)
  670. $iPage = 1;
  671. bx_import('BxDolMobileTemplate');
  672. $oMobileTemplate = new BxDolMobileTemplate($this->_oConfig, $this->_oDb);
  673. $oMobileTemplate->pageStart();
  674. $sCaption = _t('_' . $sUri . '_bcaption_latest');
  675. $aParams = array(
  676. 'sample_type' => 'archive',
  677. 'sample_params' => '',
  678. 'viewer_type' => $this->_oTextData->getViewerType(),
  679. 'start' => ($iPage - 1) * $iPerPage,
  680. 'count' => $iPerPage,
  681. 'filter_value' => '',
  682. );
  683. $iTotalCount = $this->_oDb->getCount($aParams);
  684. $aEntries = $iTotalCount ? $this->_oDb->getEntries($aParams) : array();
  685. if (empty($aEntries)) {
  686. $oMobileTemplate->displayNoData($sCaption);
  687. return;
  688. }
  689. foreach ($aEntries as $aEntry) {
  690. $aVars = array (
  691. 'content' => '<h2>' . $aEntry['caption'] . '</h2>' . getLocaleDate($aEntry['when_uts'], BX_DOL_LOCALE_DATE),
  692. 'url' => bx_js_string(BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'mobile_entry/' . $aEntry['id']),
  693. );
  694. echo $oMobileTemplate->parseHtmlByName('mobile_row.html', $aVars);
  695. }
  696. bx_import('BxDolPaginate');
  697. $oPaginate = new BxDolPaginate(array(
  698. 'page_url' => BX_DOL_URL_ROOT . $this->_oConfig->getBaseUri() . 'mobile_latest_entries/{page}',
  699. 'count' => $iTotalCount,
  700. 'per_page' => $iPerPage,
  701. 'page' => $iPage,
  702. ));
  703. echo $oPaginate->getMobilePaginate();
  704. $oMobileTemplate->pageCode($sCaption, false);
  705. }
  706. /**
  707. * Entry view page for mobile app
  708. */
  709. function actionMobileEntry($iId) {
  710. bx_import('BxDolMobileTemplate');
  711. $oMobileTemplate = new BxDolMobileTemplate($this->_oConfig, $this->_oDb);
  712. $oMobileTemplate->pageStart();
  713. $aParams = array(
  714. 'sample_type' => 'id',
  715. 'id' => (int)$iId,
  716. );
  717. $aEntry = $this->_oDb->getEntries($aParams);
  718. if (empty($aEntry)) {
  719. $oMobileTemplate->displayPageNotFound();
  720. return;
  721. }
  722. echo '<h1>' . $aEntry['caption'] . '</h1>';
  723. echo getLocaleDate($aEntry['when_uts'], BX_DOL_LOCALE_DATE);
  724. echo $aEntry['content'];
  725. $oMobileTemplate->pageCode($aEntry['caption']);
  726. }
  727. /**
  728. * Common methods
  729. */
  730. function _actFeatured($aIds, $bPositive = true) {
  731. if(!isAdmin())
  732. return false;
  733. if(is_int($aIds) || is_string($aIds))
  734. $aIds = array((int)$aIds);
  735. $bResult = $this->_oDb->updateEntry($aIds, array('featured' => ($bPositive ? 1 : 0)));
  736. if($bResult)
  737. foreach($aIds as $iId) {
  738. //--- Entry -> Featured for Alerts Engine ---//
  739. bx_import('BxDolAlerts');
  740. $oAlert = new BxDolAlerts($this->_oConfig->getAlertsSystemName(), 'featured', $iId, BxDolTextData::getAuthorId());
  741. $oAlert->alert();
  742. //--- Entry -> Featured for Alerts Engine ---//
  743. }
  744. return $bResult;
  745. }
  746. function _actPublish($aIds, $bPositive = true) {
  747. if(!isAdmin())
  748. return false;
  749. if(is_int($aIds) || is_string($aIds))
  750. $aIds = array((int)$aIds);
  751. $bResult = $this->_oDb->updateEntry($aIds, array('status' => ($bPositive ? BX_TD_STATUS_ACTIVE : BX_TD_STATUS_INACTIVE)));
  752. if($bResult)
  753. foreach($aIds as $iId) {
  754. //--- Entry -> Publish/Unpublish for Alerts Engine ---//
  755. $oAlert = new BxDolAlerts($this->_oConfig->getAlertsSystemName(), ($bPositive ? 'publish' : 'unpublish'), $iId, BxDolTextData::getAuthorId());
  756. $oAlert->alert();
  757. //--- Entry -> Publish/Unpublish for Alerts Engine ---//
  758. //--- Reparse Global Tags ---//
  759. $oTags = new BxDolTags();
  760. $oTags->reparseObjTags($this->_oConfig->getTagsSystemName(), $iId);
  761. //--- Reparse Global Tags ---//
  762. //--- Reparse Global Categories ---//
  763. $oCategories = new BxDolCategories();
  764. $oCategories->reparseObjTags($this->_oConfig->getCategoriesSystemName(), $iId);
  765. //--- Reparse Global Categories ---//
  766. }
  767. return $bResult;
  768. }
  769. function _actDelete($aIds) {
  770. if(!$this->_isDeleteAllowed(true))
  771. return false;
  772. if(is_int($aIds) || is_string($aIds))
  773. $aIds = array((int)$aIds);
  774. $bResult = $this->_oDb->deleteEntries($aIds);
  775. if($bResult) {
  776. $oTags = new BxDolTags();
  777. $oCategories = new BxDolCategories();
  778. $oSubscription = new BxDolSubscription();
  779. foreach($aIds as $iId) {
  780. //--- Entry -> Delete for Alerts Engine ---//
  781. $oAlert = new BxDolAlerts($this->_oConfig->getAlertsSystemName(), 'delete', $iId, BxDolTextData::getAuthorId());
  782. $oAlert->alert();
  783. //--- Entry -> Delete for Alerts Engine ---//
  784. //--- Reparse Global Tags ---//
  785. $oTags->reparseObjTags($this->_oConfig->getTagsSystemName(), $iId);
  786. //--- Reparse Global Tags ---//
  787. //--- Reparse Global Categories ---//
  788. $oCategories->reparseObjTags($this->_oConfig->getCategoriesSystemName(), $iId);
  789. //--- Reparse Global Categories ---//
  790. //--- Remove all subscriptions ---//
  791. $oSubscription->unsubscribe(array('type' => 'object_id', 'unit' => $this->_oConfig->getSubscriptionsSystemName(), 'object_id' => $iId));
  792. //--- Remove all subscriptions ---//
  793. }
  794. }
  795. return $bResult;
  796. }
  797. function _isCommentsAllowed(&$aEntry) {
  798. return true;
  799. }
  800. function _isVotesAllowed(&$aEntry) {
  801. return true;
  802. }
  803. function _isShareAllowed(&$aEntry) {
  804. return true;
  805. }
  806. }
  807. ?>