HomeHelpTrac

source: trunk/tags.php @ 15934

Revision 15934, 12.9 KB checked in by Alexander Trofimov, 4 months ago (diff)

Code cleaning

Line 
1<?php
2
3// 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
4
5/***************************************************************************
6*                            Dolphin Smart Community Builder
7*                              -------------------
8*     begin                : Mon Mar 23 2006
9*     copyright            : (C) 2007 BoonEx Group
10*     website              : http://www.boonex.com
11* This file is part of Dolphin - Smart Community Builder
12*
13* Dolphin is free software; you can redistribute it and/or modify it under
14* the terms of the GNU General Public License as published by the
15* Free Software Foundation; either version 2 of the
16* License, or  any later version.
17*
18* Dolphin is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
19* without even the implied warranty of  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
20* See the GNU General Public License for more details.
21* You should have received a copy of the GNU General Public License along with Dolphin,
22* see license.txt file; if not, write to marketing@boonex.com
23***************************************************************************/
24
25define('BX_TAGS_ACTION_HOME', 'home');
26define('BX_TAGS_ACTION_ALL', 'all');
27define('BX_TAGS_ACTION_POPULAR', 'popular');
28define('BX_TAGS_ACTION_CALENDAR', 'calendar');
29define('BX_TAGS_ACTION_SEARCH', 'search');
30
31define('BX_TAGS_BOX_DISIGN', 1);
32define('BX_TAGS_BOX_INT_MENU', 2);
33
34require_once( 'inc/header.inc.php' );
35require_once( BX_DIRECTORY_PATH_INC . 'design.inc.php' );
36
37bx_import('BxDolTemplate');
38bx_import('BxTemplTags');
39bx_import('BxDolPageView');
40bx_import('BxTemplCalendar');
41
42$bAjaxMode = isset($_SERVER['HTTP_X_REQUESTED_WITH']) and $_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest' ? true : false;
43
44function showTags($aParam = array(), $iBoxId = 1, $sAction = '', $iBox = 0, $sTitle = '')
45{
46    $oTags = new BxTemplTags();
47
48    $oTags->getTagObjectConfig($aParam);
49
50    if (empty($oTags->aTagObjects))
51    {
52        if ($iBox & BX_TAGS_BOX_DISIGN)
53            return DesignBoxContent($sTitle, MsgBox(_t('_Empty')), 1);
54        else
55            return MsgBox(_t('_Empty'));
56    }
57
58    $aParam['type'] = isset($_GET['tags_mode']) && isset($oTags->aTagObjects[$_GET['tags_mode']]) ? $_GET['tags_mode'] : $oTags->getFirstObject();
59
60    $sCode = '';
61    if ($iBox & BX_TAGS_BOX_INT_MENU)
62        $sCode .= $oTags->getTagsInternalMenuHtml($aParam, $iBoxId, $sAction);
63    $sCode .= $oTags->display($aParam, $iBoxId, $sAction);
64
65    if ($iBox & BX_TAGS_BOX_DISIGN)
66    {
67        $aCaptionMenu = $iBox & BX_TAGS_BOX_INT_MENU ? '' : $oTags->getTagsTopMenuHtml($aParam, $iBoxId, $sAction);
68        $sCode = DesignBoxContent($sTitle, $sCode, 1, $aCaptionMenu);
69        $sCode = '<div id="page_block_' . $iBoxId . '">' . $sCode . '<div class="clear_both"></div></div>';
70        return $sCode;
71    }
72    else
73        return array(
74            $sCode,
75            ($iBox & BX_TAGS_BOX_INT_MENU ? '' : $oTags->getTagsTopMenu($aParam, $sAction)),
76            array(),
77            ($sDate ? _t('_tags_by_day') . $sDate : '')
78        );
79}
80
81class TagsCalendar extends BxTemplCalendar
82{
83    function TagsCalendar($iYear, $iMonth)
84    {
85        parent::BxTemplCalendar($iYear, $iMonth);
86    }
87
88    function display() {
89        $oSysTemplate = BxDolTemplate::getInstance();
90           
91        $aVars = array (
92            'bx_repeat:week_names' => $this->_getWeekNames (),
93            'bx_repeat:calendar_row' => $this->_getCalendar (),
94            'month_prev_url' => $this->getBaseUri () . "&year={$this->iPrevYear}&month={$this->iPrevMonth}",
95            'month_prev_name' => _t('_month_prev'),
96            'month_prev_icon' => getTemplateIcon('sys_back.png'),
97            'month_next_url' => $this->getBaseUri () . "&year={$this->iNextYear}&month={$this->iNextMonth}",
98            'month_next_name' => _t('_month_next'),
99            'month_next_icon' => getTemplateIcon('sys_next.png'),
100            'month_current' => $this->getTitle(),
101        );
102        $sHtml = $oSysTemplate->parseHtmlByName('calendar.html', $aVars);
103        $sHtml = preg_replace ('#<bx_repeat:events>.*?</bx_repeat:events>#s', '', $sHtml);
104        $oSysTemplate->addCss('calendar.css');
105        return $sHtml;
106    }
107
108    function getData()
109    {
110        $oDb = new BxDolDb();
111
112        return $oDb->getAll("SELECT *, DAYOFMONTH(`Date`) AS `Day`
113            FROM `sys_tags`
114            WHERE `Date` >= TIMESTAMP('{$this->iYear}-{$this->iMonth}-1') AND `Date` < TIMESTAMP('{$this->iNextYear}-{$this->iNextMonth}-1')");
115    }
116
117    function getBaseUri()
118    {
119        return BX_DOL_URL_ROOT . 'tags.php?action=calendar';
120    }
121
122    function getBrowseUri()
123    {
124        return BX_DOL_URL_ROOT . 'tags.php?action=calendar';
125    }
126
127    function getEntriesNames ()
128    {
129        return array(_t('_tags_single'), _t('_tags_plural'));
130    }
131
132    function _getCalendar ()
133    {
134        $sBrowseUri = $this->getBrowseUri();
135        list ($sEntriesSingle, $sEntriesMul) = $this->getEntriesNames ();
136
137        $this->_getCalendarGrid($aCalendarGrid);
138        $aRet = array ();
139        for ($i = 0; $i < 6; $i++) {
140
141            $aRow = array ('bx_repeat:cell');
142            $isRowEmpty = true;
143
144            for ($j = $this->iWeekStart; $j < $this->iWeekEnd; $j++) {
145
146                $aCell = array ();
147
148                if ($aCalendarGrid[$i][$j]['today']) {
149                    $aCell['class'] = 'sys_cal_cell sys_cal_today';
150                    $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
151                    $aCell['bx_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
152                        'num' => $aCalendarGrid[$i][$j]['num'],
153                        'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
154                        'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
155                    ));
156                    $isRowEmpty = false;
157                } elseif (isset($aCalendarGrid[$i][$j]['day'])) {
158                    $aCell['class'] = 'sys_cal_cell';
159                    $aCell['day'] = $aCalendarGrid[$i][$j]['day'];
160                    $aCell['bx_if:num'] = array ('condition' => $aCalendarGrid[$i][$j]['num'], 'content' => array(
161                        'num' => $aCalendarGrid[$i][$j]['num'],
162                        'href' => $sBrowseUri . '&year=' . $this->iYear . '&month=' . $this->iMonth . '&day=' . $aCell['day'],
163                        'entries' => 1 == $aCalendarGrid[$i][$j]['num'] ? $sEntriesSingle : $sEntriesMul,
164                    ));
165                    $isRowEmpty = false;
166                } else {
167                    $aCell['class'] = 'sys_cal_cell_blank';
168                    $aCell['day'] = '';
169                    $aCell['bx_if:num'] = array ('condition' => false, 'content' => array(
170                        'num' => '',
171                        'href' => '',
172                        'entries' => '',
173                    ));
174                }
175
176                if ($aCell)
177                    $aRow['bx_repeat:cell'][] = $aCell;
178            }
179
180            if ($aRow['bx_repeat:cell'] && !$isRowEmpty) {
181                $aRet[] = $aRow;
182            }
183        }
184        return $aRet;
185    }
186
187}
188
189class TagsHomePage extends BxDolPageView
190{
191    var $sPage;
192
193    function TagsHomePage()
194    {
195        $this->sPage = 'tags_home';
196        parent::BxDolPageView($this->sPage);
197    }
198
199    function getBlockCode_Recent($iBlockId)
200    {
201        $aParam = array(
202            'orderby' => 'recent',
203            'limit' => getParam('tags_show_limit'),
204        );
205
206        return showTags($aParam, $iBlockId, BX_TAGS_ACTION_HOME, BX_TAGS_BOX_INT_MENU, _t('_tags_recent'));
207    }
208
209    function getBlockCode_Popular($iBlockId)
210    {
211        $aParam = array(
212            'orderby' => 'popular',
213            'limit' => getParam('tags_show_limit')
214        );
215
216        return showTags($aParam, $iBlockId, BX_TAGS_ACTION_HOME, 0, _t('_tags_popular'));
217    }
218}
219
220class TagsCalendarPage extends BxDolPageView
221{
222    var $sPage;
223
224    function TagsCalendarPage()
225    {
226        $this->sPage = 'tags_calendar';
227        parent::BxDolPageView($this->sPage);
228    }
229
230    function getBlockCode_Calendar($iBlockId)
231    {
232        $sYear = isset($_GET['year']) ? (int)$_GET['year'] : '';
233        $sMonth = isset($_GET['month']) ? (int)$_GET['month'] : '';
234        $oCalendar = new TagsCalendar($sYear, $sMonth);
235
236        return $oCalendar->display();
237    }
238
239    function getBlockCode_TagsDate($iBlockId)
240    {
241        if (isset($_GET['year']) && isset($_GET['month']) && isset($_GET['day']))
242        {
243            $aParam = array(
244                'pagination' => getParam('tags_perpage_browse'),
245                'date' => array(
246                    'year' => (int)$_GET['year'],
247                    'month' => (int)$_GET['month'],
248                    'day' => (int)$_GET['day']
249                )
250            );
251
252            return showTags($aParam, $iBlockId, BX_TAGS_ACTION_CALENDAR, 0, _t('_tags_by_day'));
253        }
254        else
255            return MsgBox(_t('_Empty'));
256    }
257}
258
259class TagsSearchPage extends BxDolPageView {
260
261    var $aSearchForm;
262    var $oForm;
263    var $sPage;
264
265    function TagsSearchPage()
266    {
267        $this->sPage = 'tags_search';
268        parent::BxDolPageView($this->sPage);
269
270        bx_import('BxTemplFormView');
271        $this->aSearchForm = array(
272            'form_attrs' => array(
273                'name'     => 'form_search_tags',
274                'action'   => '',
275                'method'   => 'post',
276            ),
277
278            'params' => array (
279                'db' => array(
280                    'submit_name' => 'submit_form',
281                ),
282            ),
283
284            'inputs' => array(
285                'Keyword' => array(
286                    'type' => 'text',
287                    'name' => 'Keyword',
288                    'caption' => _t('_tags_caption_keyword'),
289                    'required' => true,
290                    'checker' => array (
291                        'func' => 'length',
292                        'params' => array(1, 100),
293                        'error' => _t ('_tags_err_keyword'),
294                    ),
295                    'db' => array (
296                        'pass' => 'Xss',
297                    ),
298                ),
299                'Submit' => array (
300                    'type' => 'submit',
301                    'name' => 'submit_form',
302                    'value' => _t('_Submit'),
303                    'colspan' => true,
304                ),
305            ),
306        );
307
308        $this->oForm = new BxTemplFormView($this->aSearchForm);
309        $this->oForm->initChecker();
310    }
311
312    function getBlockCode_Form()
313    {
314        return BxDolTemplate::getInstance()->parseHtmlByName('search_tags_box.html', array('form' => $this->oForm->getCode()));
315    }
316
317    function getBlockCode_Founded($iBlockId)
318    {
319        $aParam = array(
320            'pagination' => getParam('tags_perpage_browse')
321        );
322
323        $sFilter = bx_get('filter');
324        if ($sFilter !== false)
325            $aParam['filter'] = process_db_input($sFilter);
326        else if ($this->oForm->isSubmittedAndValid())
327            $aParam['filter'] = $this->oForm->getCleanValue('Keyword');
328
329        if (isset($aParam['filter']))
330            return showTags($aParam, $iBlockId, BX_TAGS_ACTION_SEARCH, 0, _t('_tags_founded_tags'));
331        else
332            return MsgBox(_t('_Empty'));
333    }
334}
335
336function getPage_Home()
337{
338    $oHomePage = new TagsHomePage();
339
340    return $oHomePage->getCode();
341}
342
343function getPage_All()
344{
345    $aParam = array(
346        'pagination' => getParam('tags_perpage_browse')
347    );
348
349    return showTags($aParam, 1, BX_TAGS_ACTION_ALL, BX_TAGS_BOX_DISIGN, _t('_all_tags'));
350}
351
352function getPage_Popular()
353{
354    $aParam = array(
355        'orderby' => 'popular',
356        'limit' => getParam('tags_show_limit')
357    );
358
359    return showTags($aParam, 2, BX_TAGS_ACTION_POPULAR, BX_TAGS_BOX_DISIGN, _t('_popular_tags'));
360}
361
362function getPage_Calendar()
363{
364    $oCalendarPage = new TagsCalendarPage();
365
366    return $oCalendarPage->getCode();
367}
368
369function getPage_Search()
370{
371    $oSearchPage = new TagsSearchPage();
372
373    return $oSearchPage->getCode();
374}
375
376$sAction = empty($_GET['action']) ? '' : $_GET['action'];
377switch ($sAction)
378{
379    case BX_TAGS_ACTION_POPULAR:
380        $sContent = getPage_Popular();
381        break;
382
383    case BX_TAGS_ACTION_ALL:
384        $sContent = getPage_All();
385        break;
386
387    case BX_TAGS_ACTION_CALENDAR:
388        $sContent = getPage_Calendar();
389        break;
390
391    case BX_TAGS_ACTION_SEARCH:
392        $sContent = getPage_Search();
393        break;
394
395    default:
396        $sContent = getPage_Home();
397}
398
399if (!$bAjaxMode) {
400    check_logged();
401
402    bx_import('BxDolTemplate');
403    $oTemplate = BxDolTemplate::getInstance();
404    $oTemplate->setPageNameIndex(25);
405    $oTemplate->setPageParams(array(
406        'header' => _t('_Tags'),
407        'header_text' => _t('_Tags'),
408    ));
409    $oTemplate->setPageContent('page_main_code', $sContent);
410    PageCode();
411}
412else
413    echo $sContent;
Note: See TracBrowser for help on using the repository browser.