tags.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. // TODO: reconsider almost all functionality in this file, according to new concept it should NOT be separate page with all tags, every module has its own page with tags
  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. define('BX_TAGS_ACTION_HOME', 'home');
  23. define('BX_TAGS_ACTION_ALL', 'all');
  24. define('BX_TAGS_ACTION_POPULAR', 'popular');
  25. define('BX_TAGS_ACTION_CALENDAR', 'calendar');
  26. define('BX_TAGS_ACTION_SEARCH', 'search');
  27. define('BX_TAGS_BOX_DISIGN', 1);
  28. define('BX_TAGS_BOX_INT_MENU', 2);
  29. require_once( 'inc/header.inc.php' );
  30. require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
  31. bx_import('BxDolTemplate');
  32. bx_import('BxTemplTags');
  33. bx_import('BxDolPageView');
  34. bx_import('BxTemplCalendar');
  35. $bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
  36. function showTags($aParam = array(), $iBoxId = 1, $sAction = '', $iBox = 0, $sTitle = '')
  37. {
  38. $oTags = new BxTemplTags();
  39. $oTags->getTagObjectConfig($aParam);
  40. if (empty($oTags->aTagObjects))
  41. {
  42. if ($iBox & BX_TAGS_BOX_DISIGN)
  43. return DesignBoxContent($sTitle, MsgBox(_t('_Empty')), 1);
  44. else
  45. return MsgBox(_t('_Empty'));
  46. }
  47. $aParam['type'] = isset($_GET['tags_mode']) && isset($oTags->aTagObjects[$_GET['tags_mode']]) ? $_GET['tags_mode'] : $oTags->getFirstObject();
  48. $sCode = '';
  49. if ($iBox & BX_TAGS_BOX_INT_MENU)
  50. $sCode .= $oTags->getTagsInternalMenuHtml($aParam, $iBoxId, $sAction);
  51. $sCode .= $oTags->display($aParam, $iBoxId, $sAction);
  52. if ($iBox & BX_TAGS_BOX_DISIGN)
  53. {
  54. $aCaptionMenu = $iBox & BX_TAGS_BOX_INT_MENU ? '' : $oTags->getTagsTopMenuHtml($aParam, $iBoxId, $sAction);
  55. $sCode = DesignBoxContent($sTitle, $sCode, 1, $aCaptionMenu);
  56. $sCode = '<div id="page_block_' . $iBoxId . '">' . $sCode . '<div class="clear_both"></div></div>';
  57. return $sCode;
  58. }
  59. else
  60. return array(
  61. $sCode,
  62. ($iBox & BX_TAGS_BOX_INT_MENU ? '' : $oTags->getTagsTopMenu($aParam, $sAction)),
  63. array(),
  64. ($sDate ? _t('_tags_by_day') . $sDate : '')
  65. );
  66. }
  67. class TagsCalendar extends BxTemplCalendar
  68. {
  69. function TagsCalendar($iYear, $iMonth)
  70. {
  71. parent::BxTemplCalendar($iYear, $iMonth);
  72. }
  73. function display() {
  74. $oSysTemplate = BxDolTemplate::getInstance();
  75. $aVars = array (
  76. 'bx_repeat:week_names' => $this->_getWeekNames (),
  77. 'bx_repeat:calendar_row' => $this->_getCalendar (),
  78. 'month_prev_url' => $this->getBaseUri () . "&year={$this->iPrevYear}&month={$this->iPrevMonth}",
  79. 'month_prev_name' => _t('_month_prev'),
  80. 'month_prev_icon' => getTemplateIcon('sys_back.png'),
  81. 'month_next_url' => $this->getBaseUri () . "&year={$this->iNextYear}&month={$this->iNextMonth}",
  82. 'month_next_name' => _t('_month_next'),
  83. 'month_next_icon' => getTemplateIcon('sys_next.png'),
  84. 'month_current' => $this->getTitle(),
  85. );
  86. $sHtml = $oSysTemplate->parseHtmlByName('calendar.html', $aVars);
  87. $sHtml = preg_replace ('#<bx_repeat:events>.*?</bx_repeat:events>#s', '', $sHtml);
  88. $oSysTemplate->addCss('calendar.css');
  89. return $sHtml;
  90. }
  91. function getData()
  92. {
  93. $oDb = new BxDolDb();
  94. return $oDb->getAll("SELECT *, DAYOFMONTH(`Date`) AS `Day`
  95. FROM `sys_tags`
  96. WHERE `Date` >= TIMESTAMP('{$this->iYear}-{$this->iMonth}-1') AND `Date` < TIMESTAMP('{$this->iNextYear}-{$this->iNextMonth}-1')");
  97. }
  98. function getBaseUri()
  99. {
  100. return BX_DOL_URL_ROOT . 'tags.php?action=calendar';
  101. }
  102. function getBrowseUri()
  103. {
  104. return BX_DOL_URL_ROOT . 'tags.php?action=calendar';
  105. }
  106. function getEntriesNames ()
  107. {
  108. return array(_t('_tags_single'), _t('_tags_plural'));
  109. }
  110. function _getCalendar ()
  111. {
  112. $sBrowseUri = $this->getBrowseUri();
  113. list ($sEntriesSingle, $sEntriesMul) = $this->getEntriesNames ();
  114. $this->_getCalendarGrid($aCalendarGrid);
  115. $aRet = array ();
  116. for ($i = 0; $i < 6; $i++) {
  117. $aRow = array ('bx_repeat:cell');
  118. $isRowEmpty = true;
  119. for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) {
  120. $aCell = array ();
  121. if ($aCalendarGrid[$i][$j]['today']) {
  122. $aCell['class'] = 'sys_cal_cell sys_cal_today';
  123. $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
  124. $aCell['bx_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
  125. 'num' => $aCalendarGrid[$i][$j]['num'],
  126. 'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
  127. 'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
  128. ));
  129. $isRowEmpty = false;
  130. } elseif (isset($aCalendarGrid[$i][$j]['day'])) {
  131. $aCell['class'] = 'sys_cal_cell';
  132. $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
  133. $aCell['bx_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
  134. 'num' => $aCalendarGrid[$i][$j]['num'],
  135. 'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
  136. 'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
  137. ));
  138. $isRowEmpty = false;
  139. } else {
  140. $aCell['class'] = 'sys_cal_cell_blank';
  141. $aCell['day'] = '';
  142. $aCell['bx_if:num'] = array ('condition' => false, 'content' => array(
  143. 'num' => '',
  144. 'href' => '',
  145. 'entries' => '',
  146. ));
  147. }
  148. if ($aCell)
  149. $aRow['bx_repeat:cell'][] = $aCell;
  150. }
  151. if ($aRow['bx_repeat:cell'] && !$isRowEmpty) {
  152. $aRet[] = $aRow;
  153. }
  154. }
  155. return $aRet;
  156. }
  157. }
  158. class TagsHomePage extends BxDolPageView
  159. {
  160. var $sPage;
  161. function TagsHomePage()
  162. {
  163. $this->sPage = 'tags_home';
  164. parent::BxDolPageView($this->sPage);
  165. }
  166. function getBlockCode_Recent($iBlockId)
  167. {
  168. $aParam = array(
  169. 'orderby' => 'recent',
  170. 'limit' => getParam('tags_show_limit'),
  171. );
  172. return showTags($aParam, $iBlockId, BX_TAGS_ACTION_HOME, BX_TAGS_BOX_INT_MENU, _t('_tags_recent'));
  173. }
  174. function getBlockCode_Popular($iBlockId)
  175. {
  176. $aParam = array(
  177. 'orderby' => 'popular',
  178. 'limit' => getParam('tags_show_limit')
  179. );
  180. return showTags($aParam, $iBlockId, BX_TAGS_ACTION_HOME, 0, _t('_tags_popular'));
  181. }
  182. }
  183. class TagsCalendarPage extends BxDolPageView
  184. {
  185. var $sPage;
  186. function TagsCalendarPage()
  187. {
  188. $this->sPage = 'tags_calendar';
  189. parent::BxDolPageView($this->sPage);
  190. }
  191. function getBlockCode_Calendar($iBlockId)
  192. {
  193. $sYear = isset($_GET['year']) ? (int)$_GET['year'] : '';
  194. $sMonth = isset($_GET['month']) ? (int)$_GET['month'] : '';
  195. $oCalendar = new TagsCalendar($sYear, $sMonth);
  196. return $oCalendar->display();
  197. }
  198. function getBlockCode_TagsDate($iBlockId)
  199. {
  200. if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['day']))
  201. {
  202. $aParam = array(
  203. 'pagination' => getParam('tags_perpage_browse'),
  204. 'date' => array(
  205. 'year' => (int)$_GET['year'],
  206. 'month' => (int)$_GET['month'],
  207. 'day' => (int)$_GET['day']
  208. )
  209. );
  210. return showTags($aParam, $iBlockId, BX_TAGS_ACTION_CALENDAR, 0, _t('_tags_by_day'));
  211. }
  212. else
  213. return MsgBox(_t('_Empty'));
  214. }
  215. }
  216. class TagsSearchPage extends BxDolPageView {
  217. var $aSearchForm;
  218. var $oForm;
  219. var $sPage;
  220. function TagsSearchPage()
  221. {
  222. $this->sPage = 'tags_search';
  223. parent::BxDolPageView($this->sPage);
  224. bx_import('BxTemplFormView');
  225. $this->aSearchForm = array(
  226. 'form_attrs' => array(
  227. 'name' => 'form_search_tags',
  228. 'action' => '',
  229. 'method' => 'post',
  230. ),
  231. 'params' => array (
  232. 'db' => array(
  233. 'submit_name' => 'submit_form',
  234. ),
  235. ),
  236. 'inputs' => array(
  237. 'Keyword' => array(
  238. 'type' => 'text',
  239. 'name' => 'Keyword',
  240. 'caption' => _t('_tags_caption_keyword'),
  241. 'required' => true,
  242. 'checker' => array (
  243. 'func' => 'length',
  244. 'params' => array(1, 100),
  245. 'error' => _t ('_tags_err_keyword'),
  246. ),
  247. 'db' => array (
  248. 'pass' => 'Xss',
  249. ),
  250. ),
  251. 'Submit' => array (
  252. 'type' => 'submit',
  253. 'name' => 'submit_form',
  254. 'value' => _t('_Submit'),
  255. 'colspan' => true,
  256. ),
  257. ),
  258. );
  259. $this->oForm = new BxTemplFormView($this->aSearchForm);
  260. $this->oForm->initChecker();
  261. }
  262. function getBlockCode_Form()
  263. {
  264. return BxDolTemplate::getInstance()->parseHtmlByName('search_tags_box.html', array('form' => $this->oForm->getCode()));
  265. }
  266. function getBlockCode_Founded($iBlockId)
  267. {
  268. $aParam = array(
  269. 'pagination' => getParam('tags_perpage_browse')
  270. );
  271. $sFilter = bx_get('filter');
  272. if ($sFilter !== false)
  273. $aParam['filter'] = process_db_input($sFilter);
  274. else if ($this->oForm->isSubmittedAndValid())
  275. $aParam['filter'] = $this->oForm->getCleanValue('Keyword');
  276. if (isset($aParam['filter']))
  277. return showTags($aParam, $iBlockId, BX_TAGS_ACTION_SEARCH, 0, _t('_tags_founded_tags'));
  278. else
  279. return MsgBox(_t('_Empty'));
  280. }
  281. }
  282. function getPage_Home()
  283. {
  284. $oHomePage = new TagsHomePage();
  285. return $oHomePage->getCode();
  286. }
  287. function getPage_All()
  288. {
  289. $aParam = array(
  290. 'pagination' => getParam('tags_perpage_browse')
  291. );
  292. return showTags($aParam, 1, BX_TAGS_ACTION_ALL, BX_TAGS_BOX_DISIGN, _t('_all_tags'));
  293. }
  294. function getPage_Popular()
  295. {
  296. $aParam = array(
  297. 'orderby' => 'popular',
  298. 'limit' => getParam('tags_show_limit')
  299. );
  300. return showTags($aParam, 2, BX_TAGS_ACTION_POPULAR, BX_TAGS_BOX_DISIGN, _t('_popular_tags'));
  301. }
  302. function getPage_Calendar()
  303. {
  304. $oCalendarPage = new TagsCalendarPage();
  305. return $oCalendarPage->getCode();
  306. }
  307. function getPage_Search()
  308. {
  309. $oSearchPage = new TagsSearchPage();
  310. return $oSearchPage->getCode();
  311. }
  312. $sAction = empty($_GET['action']) ? '' : $_GET['action'];
  313. switch ($sAction)
  314. {
  315. case BX_TAGS_ACTION_POPULAR:
  316. $sContent = getPage_Popular();
  317. break;
  318. case BX_TAGS_ACTION_ALL:
  319. $sContent = getPage_All();
  320. break;
  321. case BX_TAGS_ACTION_CALENDAR:
  322. $sContent = getPage_Calendar();
  323. break;
  324. case BX_TAGS_ACTION_SEARCH:
  325. $sContent = getPage_Search();
  326. break;
  327. default:
  328. $sContent = getPage_Home();
  329. }
  330. if (!$bAjaxMode) {
  331. check_logged();
  332. bx_import('BxDolTemplate');
  333. $oTemplate = BxDolTemplate::getInstance();
  334. $oTemplate->setPageNameIndex(25);
  335. $oTemplate->setPageParams(array(
  336. 'header' => _t('_Tags'),
  337. 'header_text' => _t('_Tags'),
  338. ));
  339. $oTemplate->setPageContent('page_main_code', $sContent);
  340. PageCode();
  341. }
  342. else
  343. echo $sContent;